Create a file object from an img tag

Let’s say that I have an img tag with a base64 src like :

<img src="data:image/jpeg;base64,/9j/4AAQS..." id="id">

How can I create a File object (containing the data of the img tag) alike an object I would get after an user chose a file from a file input ? In order to upload it to a server later.

Like that one :

File { name: "a22919a70cf8458d654642e0bc2cd881.jpg", lastModified: 1521393615000, lastModifiedDate: Date 2018-03-18T17:20:15.000Z, webkitRelativePath: "", size: 40635, type: "image/jpeg" }

I’m not looking for getting a BLOB.

53 thoughts on “Create a file object from an img tag”