标签:mime ase file key end callback ESS oda arc
[-- oss支持直接从客户端提交base64编码保存图片吗 --]
//**dataURL to blob** function dataURLtoBlob(dataurl) { debugger var 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); } return new Blob([u8arr], { type: mime }); } //**blob to dataURL** function blobToDataURL(blob, callback) { var a = new FileReader(); a.onload = function (e) { callback(e.target.result); }; a.readAsDataURL(blob); } var _file = dataURLtoBlob(c); // c就是base64字符串 //Blob_test(); function Blob_test(){ var blob; if(!window.Blob) console.log(‘不支持‘); else blob = _file; if(window.URL){ document.getElementById("mybody").innerHTML = ‘<a download href="‘ + window.URL.createObjectURL(blob) + ‘" target="_blank">文件下载</a>‘; } } Blob_test()
var form = new FormData() form.append(‘signature‘, this.ossData.signature) form.append(‘accessKey‘, this.ossData.accessKey) form.append(‘policy‘, this.ossData.policy) form.append(‘key‘, key) var _fileBlob = dataURLtoBlob(base64) // c就是base64字符串 form.append(‘file‘, _fileBlob) var req = new XMLHttpRequest() req.open(‘post‘, this.actionUrl, false) req.send(form)
标签:mime ase file key end callback ESS oda arc
原文地址:https://www.cnblogs.com/kongge/p/10960460.html