Dave's Brain

Browse - Programming Tips - How can I convert a Blob to a File?

Date: 2016may10
Language: javaScript
Platform: web

Q.  How can I convert a Blob to a File?

A.  The File constructor accepts a Blob but not in all browsers
so this seems like the best way:

function blobToFile(myblob, name) { var file = null; try { file = new File([myblob], name); } catch(error) { file = myblob; file.lastModifiedDate = new Date(); file.name = name; } return file; }

Add a comment

Sign in to add a comment
Copyright © 2008-2018, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.