admin管理员组

文章数量:1425815

var myBlob = new Blob(["This is my blob content"], {type : "text/plain"});
var fd = new FormData();
fd.append("clip",myBlob)

The Blob is working fine:

myBlob: Blob
size: 341746
type: "text/plain"

But it is not being appended to the FormData:

Why is the Blob not showing up in the FormData ?

var myBlob = new Blob(["This is my blob content"], {type : "text/plain"});
var fd = new FormData();
fd.append("clip",myBlob)

The Blob is working fine:

myBlob: Blob
size: 341746
type: "text/plain"

But it is not being appended to the FormData:

Why is the Blob not showing up in the FormData ?

Share Improve this question edited Jul 28, 2020 at 20:33 WestCoastProjects asked Jul 28, 2020 at 20:30 WestCoastProjectsWestCoastProjects 63.4k106 gold badges365 silver badges627 bronze badges 2
  • fd.append('clip', myBlob, 'blobby.txt'); By the way, localStorage properties cast to Strings when possible. – StackSlave Commented Jul 28, 2020 at 20:31
  • @StackSlave I just copied and pasted incorrectly from my code : that was actually there .. Corrected the question to show it. What is the importance of your localStorage / strings ment? – WestCoastProjects Commented Jul 28, 2020 at 20:34
Add a ment  | 

1 Answer 1

Reset to default 4

Well, actually, according to FormData specs, there is no way to inspect form data elements within a simple console.log() or debugger.

So the only way to inspect the items within it is to iterate through its entires like this:

var myBlob = new Blob(["This is my blob content"], {type : "text/plain"});
var fd = new FormData();
fd.append("clip",myBlob);

// Display the key/value pairs
for (var pair of fd.entries()) {
    console.log(pair[0]+ ', ' + pair[1]); 
}

本文标签: javascriptHow to append a Blob to FormDataStack Overflow