form-data

How to give a Blob uploaded as FormData a file name?

天大地大妈咪最大 提交于 2019-11-27 02:51:16
I am currently uploading images pasted from the clipboard with the following code: // Turns out getAsFile will return a blob, not a file var blob = event.clipboardData.items[0].getAsFile(), form = new FormData(), request = new XMLHttpRequest(); form.append("blob",blob); request.open( "POST", "/upload", true ); request.send(form); Turns out the uploaded form field with receive a name similar to this: Blob157fce71535b4f93ba92ac6053d81e3a Is there any way to set this or receive this file name client side, without doing any server side communication? Chiguireitor For Chrome and Firefox, just use

Send FormData object AND an additional parameter via ajax

こ雲淡風輕ζ 提交于 2019-11-27 01:36:31
问题 I have managed to send a FormData object like so: var formData = new FormData(); formData.append('file', this.files[0]); $.ajax({ url: urlUploadProductsFile, type: 'POST', data: formData, cache: false, contentType: false, processData: false }, 'json'); Now what I want to do is add an additional CustomerId to send to the server. The following won't work: var formData = new FormData(); formData.append('file', this.files[0]); $.ajax({ url: urlUploadProductsFile, type: 'POST', data: { "file":

Accessing FormData Values

耗尽温柔 提交于 2019-11-27 01:06:19
问题 I have a FormData object which I create in javascript from an HTML form like so. The FormData object doesn't seem very well documented (it may just be me searching the wrong things!). var form = new FormData(document.getElementById("form")); My Question How do I access the different input values of this FormData object before I send it off? Eg. form.name accesses the value that was entered into the input with the name form.name . 回答1: It seems you can't get values of the form element using

FormData created from an existing form seems empty when I log it [duplicate]

匆匆过客 提交于 2019-11-26 22:49:29
问题 This question already has an answer here: How to inspect FormData? 15 answers I'm trying to get a set of keys (input names or similar) and values (input values) from a web form: <body> <form> <input type="text" name="banana" value="swag"> </form> <script> var form = document.querySelector('form'); var formData = new FormData(form); </script> </body> According to the FormData documentation, formData should contain the keys and values from the form. But console.log(formData) shows formData is

appending array to FormData and send via AJAX

断了今生、忘了曾经 提交于 2019-11-26 21:53:23
I'm using ajax to submit a multipart form with array, text fields and files. I append each VAR to the main data as so var attachments = document.getElementById('files'); var data= new FormData(); for (i=0; i< attachments.files.length; i++){ data.append('file', attachments.files[i]); console.log(attachments.files[i]); data.append ('headline', headline); data.append ('article', article); data.append ('arr', arr); data.append ('tag', tag); then I use the ajax function to send it to a PHP file to store inside sql DB. $.ajax({ type: "post", url: 'php/submittionform.php', cache: false, processData:

Send FormData with other field in Angular

耗尽温柔 提交于 2019-11-26 20:29:29
I have a form with two input text and one upload . I have to send it to the server but I have some problem concatenating the file with the text. The server expects this answer: "title=first_input" "text=second_input" "file=my_file.pdf" This is the html : <input type="text" ng-model="title"> <input type="text" ng-model="text"> <input type="file" file-model="myFile"/> <button ng-click="send()"> This is the Controller : $scope.title = null; $scope.text = null; $scope.send = function(){ var file = $scope.myFile; var uploadUrl = 'my_url'; blockUI.start(); Add.uploadFileToUrl(file, $scope.newPost

Convert JS Object to form data

一世执手 提交于 2019-11-26 18:52:16
问题 How can I can convert my JS Object to FormData ? The reason why I want to do this is, I have an object that I constructed out of the ~100 form field values. var item = { description: 'Some Item', price : '0.00', srate : '0.00', color : 'red', ... ... } Now I am asked to add the upload file functionality to my form which, of-course is impossible via JSON and so I am planning on moving to FormData . So is there any way that I can convert my JS object to FormData ? 回答1: If you have an object,

FormData.append(“key”, “value”) is not working

蓝咒 提交于 2019-11-26 17:09:56
Can you tell me whats wrong with this: var formdata = new FormData(); formdata.append("key", "value"); console.log(formdata); My output looks like this, I cant find my "key" - "value" pair FormData *__proto__: FormData **append: function append() { [native code] } ***arguments: null ***caller: null ***length: 0 ***name: "append" ***prototype: append ***__proto__: function Empty() {} *constructor: function FormData() { [native code] } **arguments: null **caller: null **length: 0 **name: "FormData" **prototype: FormData **toString: function toString() { [native code] } *__proto__: Object **_

fetch - Missing boundary in multipart/form-data POST

空扰寡人 提交于 2019-11-26 15:41:55
问题 thanks for stopping by. I want to send a new FormData() as the body of a POST request using the fetch api the operation looks something like this var formData = new FormData() formData.append('myfile', file, 'someFileName.csv') fetch('https://api.myapp.com', { method: 'POST', headers: { "Content-Type": "multipart/form-data" }, body: formData } ) the problem here is that the boundary, something like boundary=----WebKitFormBoundaryyEmKNDsBKjB7QEqu never makes it into the Content-Type: header it

How to convert FormData(HTML5 Object) to JSON

99封情书 提交于 2019-11-26 09:18:52
问题 How to convert HTML5 FormData object to JSON? Without Jquery and handling nested properties in FormData like a object. 回答1: You could also use forEach on the FormData object directly: var object = {}; formData.forEach(function(value, key){ object[key] = value; }); var json = JSON.stringify(object); UPDATE: And for those who prefer the same solution with ES6 arrow functions: var object = {}; formData.forEach((value, key) => {object[key] = value}); var json = JSON.stringify(object); UPDATE 2: