multipartform-data

How to process a multipart request consisting of a file and a JSON object in Spring restful service?

可紊 提交于 2019-11-28 05:26:59
I have the following resource (implemented using Spring 4.05.RELEASE) which accepts a file and a JSON object: (P.S. activityTemplate is a serializable entity class) ... @RequestMapping(value="/create", method=RequestMethod.POST) public @ResponseBody ActivityTemplate createActivityTemplate( @RequestPart ActivityTemplate activityTemplate, @RequestPart MultipartFile jarFile) { //process the file and JSON } ... and this is the form I am testing from: <form method="POST" enctype="multipart/form-data" action="http://localhost:8080/activityTemplates/create"> JSON: <input type="text" name=

ASP.NET Web API File saved as “BodyPart_3ded2bfb-40be-4183-b789-9301f93e90af”

女生的网名这么多〃 提交于 2019-11-28 05:17:44
I'm uploading files using the ASP.NET Web API. I've done this before the RC but for some reason the file is being saved as "BodyPart_3ded2bfb-40be-4183-b789-9301f93e90af" instead of the file name. The filename variable below returns this bodypart string too instead of the file name. I can't seem to figure out where I'm going wrong. Any help is appreciated. Client code: function upload() { $("#divResult").html("Uploading..."); var formData = new FormData($('form')[0]); $.ajax({ url: 'api/files/uploadfile?folder=' + $('#ddlFolders').val(), type: 'POST', success: function (data) { $("#divResult")

Android twitter4j upload image

久未见 提交于 2019-11-28 04:47:16
I have an android app through which I can successfully update the twitter status. I am using it to share links to a webpage which displays an image. I think it will be nice to have a scaled down preview of the image along with the tweet the same way instagram does. How do I upload this image along with my tweet? I had the same requirement sometimes back and finally come with the function may be it will help you too. /** * To upload a picture with some piece of text. * * * @param file The file which we want to share with our tweet * @param message Message to display with picture * @param

How do I receive a file upload in spring mvc using both multipart/form and chunked encoding?

谁说我不能喝 提交于 2019-11-28 04:23:37
I am trying to write a spring mvc method that can receive either a multipart/form or transfer-encoding chunked file upload. I can write a separate method to handle each type but I'd like to do it with the same method so i can use the same REST POST uri such as: http://host:8084/attachments/testupload Here is my best attempt so far: @RequestMapping(value = { "/testupload" }, method = RequestMethod.POST, produces = "application/json") public @ResponseBody ResponseEntity<MessageResponseModel> testUpload( @RequestParam(value = "filedata", required = false) MultipartFile filedata, final

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

跟風遠走 提交于 2019-11-28 03:09:14
How can I rewrite the following CURL command, so that it doesn't use the -F option, but still generates the exact same HTTP request? i.e. so that it passes the multipart/form-data in the body directly. curl -X POST -F example=test http://localhost:3000/test William Denniss 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

How can I handle multipart/form-data POST requests in my java servlet?

假装没事ソ 提交于 2019-11-28 01:58:00
I'm having a very hard time dealing with multipart/form-data requests with my java application server. From what I have found out, the servlet 3.0 specification provides methods such as HttpServletRequest.getParts(), which would be ideal for processing the form data uploaded to my servlet. However, this method is part of the 3.0 servlet specification, and my application server (Tomcat 6) does not support this yet. Even with a valid 3.0 web.xml file and the java EE 6 libs, I get the following exception when trying to call getParts(): java.lang.NoSuchMethodError: javax.servlet.http

C#: HttpClient, File upload progress when uploading multiple file as MultipartFormDataContent

我们两清 提交于 2019-11-28 01:41:12
问题 I'm using this code to upload multiple files and it working very well. It uses modernhttpclient library. public async Task<string> PostImages (int platform, string url, List<byte []> imageList) { try { int count = 1; var requestContent = new MultipartFormDataContent (); foreach (var image in imageList) { var imageContent = new ByteArrayContent (image); imageContent.Headers.ContentType = MediaTypeHeaderValue.Parse ("image/jpeg"); requestContent.Add (imageContent, "image" + count, "image.jpg");

RESTlet: How to process multipart/form-data requests?

痴心易碎 提交于 2019-11-28 01:40:06
问题 How do you catch incoming @Post variables when it is a multipart/form-data request? For a regular Post request I would do: @Post public void postExample(Representation entity) throws Exception{ Form form = new Form(entity); System.out.println(form.getFirstValue("something")); } But because it is a multipart/form-data request the above outputs null I'm a Java newbie so be gentle :) PS: I'm not interested in processing the incoming files, just the text fields. 回答1: This is a paste from one of

Multipart/form-data construction with android

笑着哭i 提交于 2019-11-28 01:13:50
问题 I am trying to make an HttpPost with multiPart/form-data via my android app. I have a postman test that is working with my api and the preview of that request in postman, looks like this: POST /api/0.1/content/upload HTTP/1.1 Host: 54.221.194.167 X-AUTHORIZATION: 166e649911ff424eb14446cf398bd7d6 Cache-Control: no-cache Postman-Token: 2412eba9-f72d-6f3b-b124-6070b5b26644 ----WebKitFormBoundaryE19zNvXGzXaLvS5C Content-Disposition: form-data; name="file01" {"mime_type":"image/jpeg","title":"IMG

Webapi ajax formdata upload with extra parameters

梦想与她 提交于 2019-11-27 23:14:46
I'm using jQuery ajax to upload file but want to add some parameters on webapi method, here is: var data = new FormData(); data.append("file", $("#file")[0].files[0]); data.append("myParameter", "test"); // with this param i get 404 $.ajax({ url: '/api/my/upload/', data: data, cache: false, contentType: false, processData: false, type: 'POST', success: function (data) { console.log(data); } }); The Webapi controller: public class MyController : ApiController { public string Upload(string myParameter) { return System.Web.HttpContext.Current.Request.Files.Count.ToString() + " / " + myParameter;