Search code examples
javascriptblobform-data

How to append a Blob to 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:

enter image description here

Why is the Blob not showing up in the FormData ?


Solution

  • 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]); 
    }