-3

I want to convert a blob file to a png. I tried this:

var blob = new Blob([ia], {type: 'image/png'});
$scope.farmerRegisterObj.farmerImage = blob;

I want to convert it into file object ..and should be able to append in a Formdata.

Kaiido
  • 87,051
  • 7
  • 143
  • 194
  • 1
    Here's another similar question: http://stackoverflow.com/a/7651373/841804 – Chanthu Jan 27 '17 at 11:21
  • or may be this: http://stackoverflow.com/questions/11089732/display-image-from-blob-using-javascript-and-websockets – Ashish Srivastava Jan 27 '17 at 11:22
  • A Blob is a File like object, or more exactly, a File is a Blob with a name. You can create a File object from a Blob thanks to the File constructor (check browser support), but this will be useless in almost every use cases. All you can do with a File can be done with a Blob. – Kaiido Jan 27 '17 at 11:36

1 Answers1

0

A Blob is a File like object, or more exactly, a File object is a Blob with a name property.

You can create a File object from a Blob thanks to the File(blob, name) constructor, but this will be useless in almost every use cases*.

All you can do with a File can be done with a Blob.

For instance, in your case, you can append a Blob directly into a FormData so that it is sent as a file/multipart :

var form = new FormData();
form.append(fieldName, blob, fileName);

* I only used it once, while trying to hack the behavior of browsers default page title when viewing a file like an image in a tab, and it only partially worked only in FF. If someone has real use cases where a File is needed, I'd be glad to know about it.

Kaiido
  • 87,051
  • 7
  • 143
  • 194