IE tries to download json response while submitting jQuery multipart form data containing file

You can simply return JSON from the controller as “text/html” and then parse it on the client side using JQuery.parseJSON(). Controller: return this.Json( new { prop1 = 5, prop2 = 10 }, “text/html”); Client side: jsonResponse = $.parseJSON(response); if(jsonResponse.prop1==5) { … } This solution has been working for me.

How to add both file and JSON body in a FastAPI POST request?

As per FastAPI documentation: You can declare multiple Form parameters in a path operation, but you can’t also declare Body fields that you expect to receive as JSON, as the request will have the body encoded using application/x-www-form-urlencoded instead of application/json (when the form includes files, it is encoded as multipart/form-data). This is not a … Read more

How to send Multipart form data with restTemplate Spring-mvc

Reading the whole file in a ByteArrayResource can be a memory consumption issue with large files. You can proxy a file upload in a spring mvc controller using a InputStreamResource: @RequestMapping(value = “/upload”, method = RequestMethod.POST) public ResponseEntity<?> uploadImages(@RequestPart(“images”) final MultipartFile[] files) throws IOException { LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>(); String response; HttpStatus httpStatus … Read more

Retrofit Uploading multiple images to a single key

We can use MultipartBody.Part array to upload an array of images to a single key. Here is the solution WebServicesAPI @Multipart @POST(WebServices.UPLOAD_SURVEY) Call<UploadSurveyResponseModel> uploadSurvey(@Part MultipartBody.Part[] surveyImage, @Part MultipartBody.Part propertyImage, @Part(“DRA”) RequestBody dra); Here is the method for uploading the files. private void requestUploadSurvey () { File propertyImageFile = new File(surveyModel.getPropertyImagePath()); RequestBody propertyImage = RequestBody.create(MediaType.parse(“image/*”), propertyImageFile); … Read more

How can I rewrite this CURL multipart/form-data request without using -F?

Solved: curl \ -X POST \ -H “Content-Type: multipart/form-data; boundary=—————————-4ebf00fbcf09″ \ –data-binary @test.txt \ http://localhost:3000/test Where test.txt contains the following text, and most importantly has CRLF (\r\n) line endings: ——————————4ebf00fbcf09 Content-Disposition: form-data; name=”example” test ——————————4ebf00fbcf09– Notes: it is important to use –data-binary instead of plain old -d as the former preserves the line endings (which … Read more

React.js, how to send a multipart/form-data to server

We just try to remove our headers and it works! fetch(“http://localhost:8910/taskCreationController/createStoryTask”, { mode: ‘no-cors’, method: “POST”, body: data }).then(function (res) { if (res.ok) { alert(“Perfect! “); } else if (res.status == 401) { alert(“Oops! “); } }, function (e) { alert(“Error submitting form!”); });

NodeJS, Axios – post file from local server to another server

The 2 oldest answers did not work for me. This, however, did the trick: const FormData = require(‘form-data’); // npm install –save form-data const form = new FormData(); form.append(‘file’, fs.createReadStream(file.path)); const request_config = { headers: { ‘Authorization’: `Bearer ${access_token}`, …form.getHeaders() } }; return axios.post(url, form, request_config); form.getHeaders() returns an Object with the content-type as well … Read more