multipartform-data

File upload of CommonsMultipartFile using RestTemplate is failing

核能气质少年 提交于 2020-01-06 04:35:11
问题 I'm trying to consume a web service that accepts a CommonsMultipartFile in the request. So, I created an HTTP client using Spring's RestTemplate. Below is the method that takes in URI and a MultipartFile as parameters. I'm trying to pass this file to the web service in the form of ByteArrayResource. public String upload(String uri, MultipartFile file) throws IOException { logger.info("URI: " + uri); ByteArrayResource fileAsResource = new ByteArrayResource(file.getBytes()) { @Override public

Post a string as multipart/form-data using requests

半腔热情 提交于 2020-01-05 09:23:56
问题 I am posting to an API that seems to insist on receiving XML data as multipart/form-data with the name (file name?) xml. It works in postman but I can't get it to work using Python's requests. This is my Python code (based on https://stackoverflow.com/a/24443309/1011724): requests.post(callpro_url, files={'xml':('data.xml',result)}, verify=False).text where result is a string containing XML. If I try this code I get the response: xml post field is empty which is the response this API give if

Where and how do I set the correct encoding when uploading files using xhr

假如想象 提交于 2020-01-05 08:02:11
问题 I am uploading image files, and I need them to work with accented characters - so I have made everything use UTF-8 . I use this javascript function to upload them: $('#files').change(function(e) { var formData = new FormData(); for (var i=0; i<this.files.length;i++){ formData.append(this.files[i].name, this.files[i]); } var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function(e) { if ( 4 == this.readyState ) { showMessage("Uploaded."); } }; xhr.open('post', 'accoms/upload.jsp', true)

Using jQuery to send data from a multipart/form-data through ajax

别来无恙 提交于 2020-01-05 07:28:29
问题 I've been working on this all day now, and I just can't get it working. I have basically got a simple ajax request using the jQuery library and I want to send the data which I post through a mutlipart/form-data file input, however, I have tried everything I can think of. My File upload script is in place awaiting the file name as a parameter (tried without also), but it just doesn't want to get the data from the file input box itself. Could someone please enlighten me on how to do this

Problem with FileUpload - Null Value for Multipart File

你离开我真会死。 提交于 2020-01-05 05:37:08
问题 I am working on a Spring web application and need to implement a simple FileUpload for one of my pages. The page for the JSP contains the following snippet of code which included an upload field for uploading the file. <form:form commandName="editMemberInfoModelObj" method="post" enctype="multipart/form-data"> <h1>Edit Member Information</h1> <table> //Other Form Input Fields ... <tr> <td>File</td> <td><input type="file" name="file"/></td> </tr> <tr> <td><input type="submit" value="Update

Mule ESB and “multipart/form-data”

三世轮回 提交于 2020-01-05 04:49:20
问题 I have a working Web service that allows me to upload a file. I'd like to put Mule 3 in front of it but I have not been successful in getting it to pass along payloads whose MIME type is "multipart/form-data". Attempts to do so produce a 400 error: "The request sent by the client was syntactically incorrect (Bad Request)." The following flow (which doesn't accomplish my purpose but serves as a test) works fine, passing along whatever text I POSTed. <flow name="Flow1" doc:name="Flow1"> <http

Spring-boot MultipartFile issue with ByteArrayResource

你离开我真会死。 提交于 2020-01-05 03:37:23
问题 I'm trying to implement a rest api consuming excel file. I'm using spring-boot and code is available here. Code works fine when using FileSystemResource for payload. But i'm not able to make the code work with ByteArrayResource in replacement of FileSystemResource : RestApi.java: @RestController public class RestApi { private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); @PostMapping("/api/upload") public ResponseEntity<?> uploadFile(@RequestParam

FormData POST request throws Network error

南笙酒味 提交于 2020-01-03 18:45:08
问题 I have a react native app that allows users to upload images to the server along with additional data. I'm using NodeJS and ExpressJS as my backend framework. The route for posting images: router.post("/", checkAuth, upload.single("gallery_item_image"), function (req, res, next) { Branch .findById({ _id: req.body.branch_id }) .exec() .then((doc) => { if(!doc) { return res.status(404).json({ message: "Invalid Branch ID", }) } galleryItem = new GalleryItem({ _id: mongoose.Types.ObjectId(),

How to save image server side when send from javascript

只愿长相守 提交于 2020-01-02 10:58:38
问题 I'm was making a drag and drop upload script by reading a bunch of tutorials, but they only cover the javascript part, and i'm having issues on the php part. I'm uploading a image as this: $('#drop-zone').bind('drop', drop); function drop(e) { e.stopPropagation(); e.preventDefault(); e.dataTransfer = e.originalEvent.dataTransfer; traverseFiles(e.dataTransfer.files); } traverseFiles makes a foreach loop for every file and calls upload funcion, there i do this: xhr = new XMLHttpRequest(); /

Spring Multipart File with @RequestBody

ぃ、小莉子 提交于 2020-01-02 07:01:37
问题 I am trying to upload data from an app to a spring backend service. Things to upload are a DataModel containing data of the object to create and several images linked to the data. Therefore I am using this method signature: @RequestMapping(method = RequestMethod.POST) @ResponseBody public Survey createSurvey(@RequestBody SurveyPostHelper helper, @RequestParam(value="file", required = true) MultipartFile[] images) I tried to play with the annotations, but either I get a blank images array or