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

Upload image with multipart form-data iOS in Swift

No Need to use any library for upload images using multipart request. Swift 4.2 func uploadImage(paramName: String, fileName: String, image: UIImage) { let url = URL(string: “http://api-host-name/v1/api/uploadfile/single”) // generate boundary string using a unique per-app string let boundary = UUID().uuidString let session = URLSession.shared // Set the URLRequest to POST and to the specified URL … Read more

Jersey 2 injection source for multipart formdata

You need to enable MultiPart feature on your application. Enabling this feature injects necessary message body readers, writers to your Jersey 2 application. Here is how you register them: On the server-side (http-server): final ResourceConfig resourceConfig = new ResourceConfig(MultiPartResource.class); resourceConfig.register(MultiPartFeature.class); On the server-side (servlet deployment): import org.glassfish.jersey.filter.LoggingFilter; import org.glassfish.jersey.media.multipart.MultiPartFeature; import javax.ws.rs.core.Application; import java.util.HashSet; import java.util.Set; … Read more

Send multipart/form-data files with angular using $http

Take a look at the FormData object: https://developer.mozilla.org/en/docs/Web/API/FormData this.uploadFileToUrl = function(file, uploadUrl){ var fd = new FormData(); fd.append(‘file’, file); $http.post(uploadUrl, fd, { transformRequest: angular.identity, headers: {‘Content-Type’: undefined} }) .success(function(){ }) .error(function(){ }); }

What is the boundary parameter in an HTTP multi-part (POST) Request?

To quote from the RFC 1341, section 7.2.1, what I consider to be the relevant bits on the boundary parameter of the Content-Type header (for MIME): All subtypes of “multipart” share a common syntax … The Content-Type field for multipart entities requires one parameter, “boundary”, which is used to specify the encapsulation boundary. The encapsulation … Read more

How to upload multipart form data and image to server in android?

If like me you were struggling with multipart upload. Here’s a solution using 95% of code from this Android snippet. public String multipartRequest(String urlTo, Map<String, String> parmas, String filepath, String filefield, String fileMimeType) throws CustomException { HttpURLConnection connection = null; DataOutputStream outputStream = null; InputStream inputStream = null; String twoHyphens = “–“; String boundary = … 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

Send FormData with other field in AngularJS

Don’t serialize FormData with POSTing to server. Do this: this.uploadFileToUrl = function(file, title, text, uploadUrl){ var payload = new FormData(); payload.append(“title”, title); payload.append(‘text’, text); payload.append(‘file’, file); return $http({ url: uploadUrl, method: ‘POST’, data: payload, //assign content-type as undefined, the browser //will assign the correct boundary for us headers: { ‘Content-Type’: undefined}, //prevents serializing payload. don’t … Read more

Node.js (with express & bodyParser): unable to obtain form-data from post request

In general, an express app needs to specify the appropriate body-parser middleware in order for req.body to contain the body. [EDITED] If you required parsing of url-encoded (non-multipart) form data, as well as JSON, try adding: // Put this statement near the top of your module var bodyParser = require(‘body-parser’); // Put these statements before … Read more