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

How to set up a Web API controller for multipart/form-data

I normally use the HttpPostedFileBase parameter only in Mvc Controllers. When dealing with ApiControllers try checking the HttpContext.Current.Request.Files property for incoming files instead: [HttpPost] public string UploadFile() { var file = HttpContext.Current.Request.Files.Count > 0 ? HttpContext.Current.Request.Files[0] : null; if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine( … 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

Apache HttpClient making multipart form post

Use MultipartEntityBuilder from the HttpMime library to perform the request you want. In my project I do that this way: HttpEntity entity = MultipartEntityBuilder .create() .addTextBody(“number”, “5555555555”) .addTextBody(“clip”, “rickroll”) .addBinaryBody(“upload_file”, new File(filePath), ContentType.APPLICATION_OCTET_STREAM, “filename”) .addTextBody(“tos”, “agree”) .build(); HttpPost httpPost = new HttpPost(“http://some-web-site”); httpPost.setEntity(entity); HttpResponse response = httpClient.execute(httpPost); HttpEntity result = response.getEntity(); Hope this will help. … Read more

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

How do I set multipart in axios with react?

Here’s how I do file upload in react using axios import React from ‘react’ import axios, { post } from ‘axios’; class SimpleReactFileUpload extends React.Component { constructor(props) { super(props); this.state ={ file:null } this.onFormSubmit = this.onFormSubmit.bind(this) this.onChange = this.onChange.bind(this) this.fileUpload = this.fileUpload.bind(this) } onFormSubmit(e){ e.preventDefault() // Stop form submit this.fileUpload(this.state.file).then((response)=>{ console.log(response.data); }) } onChange(e) { … 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;

Example of multipart/form-data

EDIT: I am maintaining a similar, but more in-depth answer at: https://stackoverflow.com/a/28380690/895245 To see exactly what is happening, use nc -l or an ECHO server and an user agent like a browser or cURL. Save the form to an .html file: <form action=”http://localhost:8000″ method=”post” enctype=”multipart/form-data”> <p><input type=”text” name=”text” value=”text default”> <p><input type=”file” name=”file1″> <p><input type=”file” … 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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)