Uploading file using POST request in Node.js

Looks like you’re already using request module. in this case all you need to post multipart/form-data is to use its form feature: var req = request.post(url, function (err, resp, body) { if (err) { console.log(‘Error!’); } else { console.log(‘URL: ‘ + body); } }); var form = req.form(); form.append(‘file’, ‘<FILE_DATA>’, { filename: ‘myfile.txt’, contentType: ‘text/plain’ … Read more

POST multipart/form-data with Objective-C

The process is as follows: Create dictionary with the userName, userEmail, and userPassword parameters. NSDictionary *params = @{@”userName” : @”rob”, @”userEmail” : @”[email protected]”, @”userPassword” : @”password”}; Determine the path for the image: NSString *path = [[NSBundle mainBundle] pathForResource:@”avatar” ofType:@”png”]; Create the request: NSString *boundary = [self generateBoundaryString]; // configure the request NSMutableURLRequest *request = [[NSMutableURLRequest … Read more

How to upload file to server with HTTP POST multipart/form-data?

Basic implementation using MultipartFormDataContent :- HttpClient httpClient = new HttpClient(); MultipartFormDataContent form = new MultipartFormDataContent(); form.Add(new StringContent(username), “username”); form.Add(new StringContent(useremail), “email”); form.Add(new StringContent(password), “password”); form.Add(new ByteArrayContent(file_bytes, 0, file_bytes.Length), “profile_pic”, “hello1.jpg”); HttpResponseMessage response = await httpClient.PostAsync(“PostUrl”, form); response.EnsureSuccessStatusCode(); httpClient.Dispose(); string sd = response.Content.ReadAsStringAsync().Result;

File upload along with other object in Jersey restful web service

You can’t have two Content-Types (well technically that’s what we’re doing below, but they are separated with each part of the multipart, but the main type is multipart). That’s basically what you are expecting with your method. You are expecting mutlipart and json together as the main media type. The Employee data needs to be … Read more

MULTIPART_FORM_DATA: No injection source found for a parameter of type public javax.ws.rs.core.Response

Get rid of jersey-multipart-1.18.jar. That is for Jersey 1.x. Add these two jersey-media-multipart-2.17 mimepull-1.9.3 For Maven you would use the following dependency (you don’t need to explicitly add the mimepull dependency, as this one will pull it in). <dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-multipart</artifactId> <version>2.17</version> <!– Make sure the Jersey version matches the one you are currently using … Read more

Post multipart request with Android SDK

Update April 29th 2014: My answer is kind of old by now and I guess you rather want to use some kind of high level library such as Retrofit. Based on this blog I came up with the following solution: http://blog.tacticalnuclearstrike.com/2010/01/using-multipartentity-in-android-applications/ You will have to download additional libraries to get MultipartEntity running! 1) Download httpcomponents-client-4.1.zip … Read more

C# HttpClient 4.5 multipart/form-data upload

my result looks like this: public static async Task<string> Upload(byte[] image) { using (var client = new HttpClient()) { using (var content = new MultipartFormDataContent(“Upload—-” + DateTime.Now.ToString(CultureInfo.InvariantCulture))) { content.Add(new StreamContent(new MemoryStream(image)), “bilddatei”, “upload.jpg”); using ( var message = await client.PostAsync(“http://www.directupload.net/index.php?mode=upload”, content)) { var input = await message.Content.ReadAsStringAsync(); return !string.IsNullOrWhiteSpace(input) ? Regex.Match(input, @”http://\w*\.directupload\.net/images/\d*/\w*\.[a-z]{3}”).Value : null; } … Read more

How to send a “multipart/form-data” with requests in python?

Basically, if you specify a files parameter (a dictionary), then requests will send a multipart/form-data POST instead of a application/x-www-form-urlencoded POST. You are not limited to using actual files in that dictionary, however: >>> import requests >>> response = requests.post(‘http://httpbin.org/post’, files=dict(foo=’bar’)) >>> response.status_code 200 and httpbin.org lets you know what headers you posted with; in … Read more

How to send FormData objects with Ajax-requests in jQuery? [duplicate]

I believe you could do it like this : var fd = new FormData(); fd.append( ‘file’, input.files[0] ); $.ajax({ url: ‘http://example.com/script.php’, data: fd, processData: false, contentType: false, type: ‘POST’, success: function(data){ alert(data); } }); Notes: Setting processData to false lets you prevent jQuery from automatically transforming the data into a query string. See the docs … Read more