I am trying to get a static .json file from my angular $http request, but it appears ServiceStack has a handle on all *.json requests. Is it possible to GET a physical json file?
Here is the error I get:
Forbidden
Request.HttpMethod: GET
Request.PathInfo: /app/resources/menu/administrator.json
Request.QueryString:
Request.RawUrl: /app/resources/menu/administrator.json
By default ServiceStack only serves static files with pre-configured safe file extensions.
You can add static.json files to the allowed white-list with:
SetConfig(new HostConfig {
AllowFileExtensions = { "json" },
});
Related
The API's Documentation said I should put in Body Params:
restaurant_token:(required)string -> API Access Token providen by Tiller
provider_token:(required)string -> API Access Token providen by Tiller
inventory:(required)file -> Inventory import file
clear:(booleantrue) -> remove existing items or not
My POST request is :
https://app.tillersystems.com/api/inventory/import
And my JSON is:
{
"provider_token": "xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"restaurant_token": "xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"inventory": "C://Mes Projets//N74_Interface_Sage_Tiller//Exe//Traitement//Articles_SAGE_20210826172848541.csv",
"clear": true
}
The request's answer is:
{
"import": false,
"message": "Missing \"inventory\" file field."
}
You can encode file to base64 and put it as string like this
But I think the best solution is to use standard file sharing protocols
To send large files, in any case, you will have to send them in their original form, without convertation to base64
To download files on the client, you can receive data about the file in the json format, which will include the generated link to download the file using the standard protocol
i worked with Angular +9 and i've a problem when read json file from assets folder.
i am using the http module and the call works fine when the application is run locally, but when i run ng-build and publish the application on a server, the call to the json file doesn't work indicating the following message:
ERROR Http failure response for assets/resources/fakeData.json: 0 Unknown Error
My code:
What could be the problem? Why can't I access the assets folder directly?
Your problem is that you are trying to access your file system with the HttpClient. You can't do that. You could of course make an API Endpoint that returns your json file, but you can't access it directly like that with the HttpClient module.
Here what I would do instead:
import * as myJson from '<path to fakeData.json>';
...
getData(): any {
return myJson;
}
If you are just trying to mess around with HttpClient module and need some json to play with, you use JSON Placeholder API:
this.http.get('https://jsonplaceholder.typicode.com/todos/1');
According to the below SOF Question, it looks like you can get your local json files to be hosted along with the angular dev server if you wanted to:
Load json from local file with http.get() in angular 2
I don't know which web server you are using, but it looks like your web server does not support hosting of JSON-files.
Apache: use the AddType directive - https://cets.seas.upenn.edu/answers/addtype.html
IIS: Add a MIME-type - https://learn.microsoft.com/en-us/iis/configuration/system.webserver/staticcontent/mimemap
In my vue.js App I have been loading all the data from an API that I have configured as baseURL in my nuxt.config.js.
Now I want to load a static json file, that does not come from that API. That file will include additional names of files to load depending on user interaction.
In order to keep my code consistent I would like to use axios.get to load the static data in the same way I do with API calls.
So far I haven't managed to do so.
I placed the json files inside my static directory an have tried to access the files like this:
const { data } = await axios.get(
'_nuxt/static/json/staticData.json',
{ baseURL: window.location.origin }
)
I can access other static files like images form the static directory, but the json file generates a 404 error.
Should I choose another directory or try a totally different approach?
I included the path segment "_nuxt/static/" because the URL of the rendered image file i checked for reference had it in there too. Turns out this is not the right URL for my Axios call. Code should be written like this:
const { data } = await axios.get(
'/json/staticData.json',
{ baseURL: window.location.origin }
)
Suppose we have a JSON file with static data for our Angular 5 app. We want to "embed" it in app scripts, so when we'd like to get data from it, the app will not make a round trip to server for it.
Can you explain how to achieve it from configuring the Angular CLI (if needed) up to the TypeScript code returning data from that JSON file?
You can simply use the json file as though it is a url endpoint in your service.
If you have say a file called foo.json in assets/foo.json you simply embed that path to your http call.
//this is in src/ directory which is one layer deep from assets
#Injectable()
export class MyService {
constructor(private http: HttpClient) { }
getData() {
return this.http.get('../assets/foo.json');
}
}
I have recorded my script to upload json file through Jmeter, but now I am facing the problem while uploading json file through jmeter which is on my local drive.
I am already done with following steps:
Either use full path to file, you're uploading, or copy it to JMeter's "bin" folder
Don't forget to tick Use multipart/form-data for HTTP POST box
Make sure you provide correct Parameter name and MIME Type
Getting exception in my response data:
{"Exception":"Object reference not set to an instance of an object."}
For me works like this. JSON example May be Your server prefer some specific headers? E.g. content type and so on
Why you're using json file?
If you facing problems with generating random JSON data, here is a JSR223 preprocessor:
import org.apache.commons.io.FileUtils;
def time = vars.get("stratup_time")
File myFile = File.createTempFile("upload-", "" );
// Generate Random length string and write to file
FileUtils.write(myFile, "{\"test\":\"$time\"", "UTF-8" )
// Store file name in variable.
vars.put( "filename", myFile.getCanonicalPath() )
And PostProcessor:
import org.apache.commons.io.FileUtils;
// Delete file and do not throw error
FileUtils.deleteQuietly(new File( vars.get("filename")));
In order to be able to record the file upload event you need to copy your .json file to JMeter's "bin" folder, this way HTTP(S) Test Script Recorder will be able to capture the request and generate necessary HTTP Request sampler. It will also populate the HTTP Header Manager
More information: Recording File Uploads with JMeter