Laravel request file upload with content-type won't work - laravel

When I remove content-type from Postman laravel request has the file, but if I add any content type in headers it is null? Problem is that browsers add content-type,and I can not exclude them to make it work? Any ideas? Thanks

You should probably get the Content-Type from the UploadedFile instead:
$request->file('form_input_name')->getClientMimeType();
The content-type of the entire request will be set to something like multipart encoding when you send a file with Postman.
I hope this helps.

Related

how to upload a.zip file in Jmeter?

I am unable to upload a .zip file from Jmeter.
Upon trying to upload the file i am getting an error like below,
{
"args":[
"unsupportedMediaType"],
"message":"Request media type is not supported",
"messageId":"unsupportedMediaType",
"correlationId":"6539cd74-5f09-473c-40d2-36f98c0a472b",
"causes":[
],
"status":415
}
HTTP Method supported: POST.
Request header:
Content-Type: application/json; charset=UTF-8
Can anyone please help me in uploading the .zip file from the Jmeter, refer to the below image for my request,
Thanks in advance.
Are you sure about your content-type and what you are doing ?
for zip content type application/json is wrong.
fileToString will try to transform byes(zip) to text which cannot work
Try
checking Use multipart/form-data for Post
and Browser compatible headers .
remove FileToString call and use last tab Files upload instead of body data. And use there the content type application/zip or something suitable
If you are trying to upload a file and send a body, you may need to use nightly build.

Laravel can't get param header in request with nginx

I'm working on a Laravel project (an API) and I have a problem with a custom param in the request header.
I need to send a token in the request header, so I just add a param api_token in my request.
When I am on my local configured with apache2, I can in Laravel get my header request param with $request->header('api_token'), but when I tr on my server configured with nginx, I always get null
For me, there is a problem with nginx and header request, what can I do ?
Any ideas ? Maybe it's not from nginx...
That's because by default Nginx does not allow header with an underscore. You can simply update your header parameter to api-token:
$request->header('api-token');
Or you can configure your Nginx configuration to allow header with an underscore. Somewhere between your server block, add underscores_in_headers directive like this:
server {
...
underscores_in_headers on;
...
}
Also don't forget to reload your Nginx configuration. Read more about this underscores_in_headers directive here.
Hope this solve your issue.

valums file-uploader IE and #Responsebody. IE Launches download dialog.

I am using valums file-uploader to upload files. This works great if my Spring controller returns void. If I add a #Responsebody Object to my controller IE things that I am about to download instead of uploading a file and launches a dialog.
The reason I would like to have a #Responsebody Object and not void is for error handling. How can I trick IE in this case?
I'm assuming that Spring is automagically setting the content-type to application/json for you, which will not work in IE. Ensure the content-type of your response is text/plain. Some will say that text/html is correct, and that is true for most cases. However, text/html will cause you problems if your JSON response contains HTML as IE will mess with the response. So, your safest bet is to ensure the content-type of your response is text/plain.
While we are on the topic of IE quirkiness, also be sure that you only return a 200 response if you intend to also include JSON in your response. IE will, by default, replace the content of "small" non-200 responses with a "friendly" message. "Small", I believe, is defined as a response that is less than 512 (or possibly 256) bytes.
For a list of all things you should be aware of when using IE, have a peek at the "limitations of IE" section in the Fine Uploader readme.

Send XML file as response to ajax

i have created a xml file from database.
this xml file i need to send as a response from my servlet to ajax.
I have checked various forums and blogs over the web and found that the response xml is created at the time when the servlet is called.
In this case i already have a xml file in my server, i just need to send it as a response to ajax.
Help !!
In your doGet() or doPost() method make sure you set the content-type before writing anything to the response. Like this...
PrintWriter pr = response.getWriter();
response.setContentType("application/xml");
//parse your data to XML
String xml = parseXml(root);
pr.write(xml);
Note: A content-type of "text/xml" should also be valid. Frameworks like JQuery and Prototype support both.

WP7 - Prevent RestSharp from caching

I use RestSharp in my Windows Phone 7.1 project.
My problem is RestSharp always cache response data.
Example:
At the first time I send request, it returns data correctly. After some delete operations, I send that request again, but response seems the same as the first time, nothing's changed.
If I stop debugging and press F5 to start again, it works perfectly as expected.
I also tried request.AddParameter("cache-control", "no-cache", ParameterType.HttpHeader); and got no luck.
How can I fix this problem?
I have the same issue so just add header that specify not to cache response data
client is my RestClient with base url and than add default header Cache-Control with value no-cache.
client.AddDefaultHeader("Cache-Control", "no-cache")
I found solution in Rico Suter comment, thanks! I will mark this as accepted anwser
its a hack but try something like url = originalUrl + "&nocache=" + DateTime.Now.Ticks
The "Cache-Control" header should do the trick!
I think HTTP Headers are case-insensitive, but the server may not agree with me there! You should try using Cache-Control instead of cache-control...
Also, I would also add the Pragma header with no-cache value to the request (some old servers don't use the "Cache-Control" header, but they will sure recognize this one)!
And I would try to use Fiddler to debug the comms and check that the headers are really being sent to the server as expected!
Another solution can be to set the "If-Modified-Since" header with value of DateTime.Now:
client.AddDefaultParameter("If-Modified-Since", DateTime.Now, ParameterType.HttpHeader);

Resources