javascript - 如何把前端的base64圖片上傳到阿里云oss
問題描述
如何把前端的base64圖片上傳到阿里云oss
問題解答
回答1:先把數(shù)據(jù)decode_base64, 然后通過
流式上傳就直接把解出來的內(nèi)容直接上傳
文件上傳,就保存為臨時文件,再按傳統(tǒng)方式上傳
回答2:你現(xiàn)在是獲取到了base64的圖片了嗎 如果是的話 那就調(diào)用oss對應(yīng)的上傳接口不就好了 如果沒有獲取到base64格式的圖片 就用下面的辦法:
init : function(options) { var oThis = this; if( typeof FileReader===’undefined’ ) { this.imgBox.innerHTML = '抱歉,你的瀏覽器不支持 FileReader'; this.file.setAttribute(’disabled’,’disabled’); } else { this.file.addEventListener(’change’, oThis.readFile.bind(this), false); } },readFile : function(event) { var file = this.file.files[0],oThis = this;console.log(this); if ( !oThis.reg.test(file.type) ) { alert('文件必須為圖片!'); return; } var reader = new FileReader(); reader.readAsDataURL(file); reader.onload = function(e) { var img = new Image(), length = this.result.length, result = this.result;img.src = result;img.onload = function () { if ( length > oThis.maxSize ) {result = oThis.compress(img); } oThis.imgBox.src = result; oThis.cb(result);}; } },compress : function(img) { var width = img.width,height = img.height,data = null; this.canvas.width = img.width; this.canvas.height = img.height; this.ctx.drawImage(img, 0, 0, width, height); data = this.canvas.toDataURL(’image/jpeg’, this.ratio); return data;}回答3:
看這里 -- http://www.jianshu.com/p/665d...
相關(guān)文章:
1. 測試自動化html元素選擇器元素ID或DataAttribute [關(guān)閉]2. html5 - datatables 加載不出來數(shù)據(jù)。3. javascript - QQ第三方登錄的問題4. html5和Flash對抗是什么情況?5. 利用IPMI遠程安裝centos報錯!6. node.js - mongodb查找子對象的名稱為某個值的對象的方法7. 運行python程序時出現(xiàn)“應(yīng)用程序發(fā)生異常”的內(nèi)存錯誤?8. 在mac下出現(xiàn)了兩個docker環(huán)境9. 正在使用electron和node.js做桌面應(yīng)用,需要實時監(jiān)聽是否有網(wǎng)絡(luò)連接,node或者electron是否可以做到10. spring-mvc - spring-session-redis HttpSessionListener失效

網(wǎng)公網(wǎng)安備