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. MySQL的聯(lián)合查詢[union]有什么實際的用處2. PHP訂單派單系統(tǒng)3. mysql的主從復(fù)制、讀寫分離,關(guān)于從的問題4. mysql - sql 左連接結(jié)果union右連接結(jié)果,導(dǎo)致重復(fù)性計算怎么解決?5. 怎么能做出標簽切換頁的效果,(文字內(nèi)容隨動)6. mysql 遠程連接出錯10060,我已經(jīng)設(shè)置了任意主機了。。。7. php多任務(wù)倒計時求助8. 數(shù)組排序,并把排序后的值存入到新數(shù)組中9. 默認輸出類型為json,如何輸出html10. mysql時間格式問題
