multipartform-data

Sending nested JSON with image

回眸只為那壹抹淺笑 提交于 2019-12-04 19:34:47
I have been trying to research a way to be able to send nested JSON requests via Ajax back to the server. From my understanding formdata that we mostly use for sending images or files to the server wont work in this scenario, since it seems like FormData does not handle nested objects. This is the kind of payload I need to send. Any suggestions? payload = { 'login':{ 'key':'some_key' }, 'user':{ 'doc':{ 'dp':<here will be the image file>, 'date':"some date", 'extra':"extra info" }, 'fingerprint':'some_fingerprint' } } I've never been able to send image data over Json, but I have been able to

How to arrange the order of data and file using requests to post multipart/form-data?

柔情痞子 提交于 2019-12-04 17:36:18
I want to arrange file in front of data. If I try the traditional way, the data appears in front of file. To be more specifically, I want myfile to appear before form_value . form_value={'exp':'python', 'ptext':'text', 'board':'Pictures'} myfile = {'up': ('aa.png', open('aa.png', 'rb'), 'image/png')} r = requests.post(url, files=myfile, data=form_value, cookies=cookie) result Content-Type: multipart/form-data; boundary=170e4a5db6d74d5fbb384dfd8f2d33ce --170e4a5db6d74d5fbb384dfd8f2d33ce Content-Disposition: form-data; name="ptext" text --170e4a5db6d74d5fbb384dfd8f2d33ce Content-Disposition:

Decoding RFC 2231 headers

我的梦境 提交于 2019-12-04 17:26:11
问题 Trying to address this issue, I'm trying to wrap my head around the various functions in the Python standard library aimed at supporting RFC 2231. The main aim of that RFC appears to be three-fold: allowing non-ASCII encoding in header parameters, noting the language of a given value, and allowing header parameters to span multiple lines. The email.util library provides several functions to deal with various aspects of this. As far as I can tell, they work as follows: decode_rfc2231 only

C#: Posting Model from body and file as MultipartFormDataContent

安稳与你 提交于 2019-12-04 16:59:35
I'm looking for a way to send model and image in one request. I tried to send my model from body, but I don't know how to send the file. Is there another way than sending image and model in a different files? Here's the POST method from my API: [HttpPost] [Route("UploadNewEvent")] public async Task<IActionResult> CreateNewEventAsync([FromBody] EventModel model) { var file = this.Request.Form.Files.LastOrDefault(); if (file != null) { var uploads = Path.Combine(_environment.WebRootPath, "uploads"); using (var fileStream = new FileStream(Path.Combine(uploads, "test.jpg"), FileMode.Create)) {

How to set a boundary on a multipart/form-data request while using jquery ajax FormData() with multiple files

主宰稳场 提交于 2019-12-04 15:26:01
问题 I have an HTML form that needs to upload 3 parts to an existing REST API in a single request. I can't seem to find documentation on how to set a boundary on a FormData submission. I've attempted to follow the examples given here: How to send FormData objects with Ajax-requests in jQuery? However when I submit the data it gets rejected with the following stacktrace: Caused by: org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found.

Javascript .files[0] attribute in jQuery

萝らか妹 提交于 2019-12-04 14:51:40
Is there an equivalent to this statement in jQuery? var value = document.getElementById(id).files[0]; Using the standard jQuery selectors with .files[0] appended doesn't appear to work, and I can't find an equivalent jQuery command to .files. Any suggestions? I'm using this to retrieve the file from an input type='file' form element. $('#id').get(0).files[0] get(0) return DOM element 来源: https://stackoverflow.com/questions/11443886/javascript-files0-attribute-in-jquery

Node.js - generate multipart/form-data

纵饮孤独 提交于 2019-12-04 13:04:44
Is there a Node.js library for generating multipart/form-data content in the following form? ------------------------------7a9cd2dc11c1 Content-Disposition: form-data; name="to" destination@email.com ------------------------------7a9cd2dc11c1 Content-Disposition: form-data; name="from" recipient@email.com ------------------------------7a9cd2dc11c1 Content-Disposition: form-data; name="subject" subject line ------------------------------7a9cd2dc11c1 Content-Disposition: form-data; name="text" This content does not matter. ------------------------------7a9cd2dc11c1-- thejh fermata looks like it

How to upload image using multipart request with Moya Swift?

本秂侑毒 提交于 2019-12-04 11:51:29
问题 I'm using Moya 10.0.1 and I'm having a problem when I'm trying to upload an image to the server. I did follow the Multipart Upload example and this is my setup code: typealias UpdateUserAvatarParameters = (userId: Int, image: UIImage) enum APITarget { case updateUserAvatar(parameters: UpdateUserAvatarParameters) } extension APITarget: TargetType { public var baseURL: URL { return URL(string: "http://domain/api")! } public var path: String { switch self { case .updateUserAvatar: return "

How to send a buffer in form-data to SignServer?

房东的猫 提交于 2019-12-04 11:17:13
I have a file in memory (in a buffer), it doesn't exist on the file system (so I can't just stream that). I'm trying to send it to SignServer using HTTP. Here's how I try to do it: var formdata = require('form-data'); var form = new formdata(); form.append('workerName', 'PDFSigner'); form.append('data', file_buffer); // or // escape(file_buffer.toString('binary')) // or // file_buffer.toString('binary') (without escaping) var request = form.submit('http://localhost:8080/signserver/process', function(err, res) {}); When I try appending file_buffer SignServer says that data is empty: Status 400

Retrofit 2 Multipart POST request sends extra quotes to PHP

随声附和 提交于 2019-12-04 10:31:59
问题 Using Retrofit 2.0.1, there is a call function in my API interface defined in Android App: @Multipart @POST("api.php") Call<ResponseBody> doAPI( @Part("lang") String lang, @Part("file\"; filename=\"image.jpg") RequestBody file ); I send the request like this: Call call = service.doAPI("eng", imageFile); where imageFile is a RequestBody created with a File object. The upload image part has no problem, while the @Part("lang") String lang part got extra quotes in server. In PHP side, it is