简体   繁体   中英

Convert Blob to Image file in Javascript

I have tried to convert blobs to image file using the below code.

var file = new File([blobs],"Download.png");

This gives me a file with type null

This is my file in console.

lastModified: 1618930293005
lastModifiedDate: Tue Apr 20 2021 07:51:33 GMT-0700 (Pacific Daylight Time) {}
name: "Download.png"
size: 3
type: ""
webkitRelativePath: ""

While I'm trying to download this file, it is downloading as a text file and not an image file. Can somebody help me with this?

I want to download the original file (ie, Image file)

You can specify the type in the third parameter:

 new File([blobs], "Download.png", { type: "image/png" })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM