|
@@ -11632,17 +11632,36 @@ U.MD.D.I.downloadFile = function (cid, s, task, t, uid, type, text, loading, spa
|
|
|
}
|
|
|
|
|
|
function dataURLtoFile_shishi(dataurl, filename) {
|
|
|
- let arr = dataurl.split(","),
|
|
|
- mime = arr[0].match(/:(.*?);/)[1],
|
|
|
- bstr = atob(arr[1]),
|
|
|
- n = bstr.length,
|
|
|
- u8arr = new Uint8Array(n);
|
|
|
- while (n--) {
|
|
|
- u8arr[n] = bstr.charCodeAt(n);
|
|
|
+ try {
|
|
|
+ if (typeof dataurl !== "string" || dataurl.indexOf(',') === -1) {
|
|
|
+ throw new Error("Invalid dataurl");
|
|
|
+ }
|
|
|
+ let arr = dataurl.split(","),
|
|
|
+ mimeMatch = arr[0].match(/:(.*?);/);
|
|
|
+ if (!mimeMatch) {
|
|
|
+ throw new Error("Mime type not found in dataurl");
|
|
|
+ }
|
|
|
+ let mime = mimeMatch[1];
|
|
|
+ let bstr = atob(arr[1]);
|
|
|
+ let n = bstr.length;
|
|
|
+ let u8arr = new Uint8Array(n);
|
|
|
+ for (let i = 0; i < n; i++) {
|
|
|
+ u8arr[i] = bstr.charCodeAt(i);
|
|
|
+ }
|
|
|
+ // Check for File constructor compatibility
|
|
|
+ if (typeof File === "function") {
|
|
|
+ return new File([u8arr], filename, { type: mime });
|
|
|
+ } else {
|
|
|
+ // fallback for very old browsers
|
|
|
+ let blob = new Blob([u8arr], { type: mime });
|
|
|
+ blob.name = filename;
|
|
|
+ return blob;
|
|
|
+ }
|
|
|
+ } catch(e) {
|
|
|
+ console.error("dataURLtoFile_shishi error:", e, dataurl, filename);
|
|
|
+ // 返回null,调用方自行判断
|
|
|
+ return null;
|
|
|
}
|
|
|
- return new File([u8arr], filename, {
|
|
|
- type: mime
|
|
|
- });
|
|
|
}
|
|
|
|
|
|
U.MD.D.I.openApplicationUpload = function (str, cid, stage, task, tool) {
|