我正在嘗試根據(jù)從Ionic的相機(jī)插件獲得的一些base64數(shù)據(jù)創(chuàng)建文件。我正在使用從另一個stackoverflow的答案中獲得的功能。問題在于創(chuàng)建的文件的大小為:0,并且name屬性似乎是我在創(chuàng)建時傳遞的Uint8array。這是轉(zhuǎn)換Base64數(shù)據(jù)的功能:(前兩行帶有注釋,因為數(shù)據(jù)的開頭沒有“ data:image / jpeg; base64”)_dataURLtoFile(dataurl, filename) { let //arr = dataurl.split(','), //mime = arr[0].match(/:(.*?);/)[1], bstr = atob(dataurl), n = bstr.length, u8arr = new Uint8Array(n); while(n--){ u8arr[n] = bstr.charCodeAt(n); } return new File([u8arr], filename, {type:'image/jpeg'}); }這是我在控制臺中得到的:File {name: Array(1), localURL: "archivo", type: {…}, lastModified: null, lastModifiedDate: null, …}end: 0lastModified: nulllastModifiedDate: nulllocalURL: "archivo"name: [Uint8Array(268175)]size: 0start: 0type: {type: "image/jpeg"}__proto__: Object
在javascript中創(chuàng)建文件時獲取大小為0
人到中年有點甜
2021-05-13 17:14:00