javascript - 如何把前端的base64圖片上傳到阿里雲oss
phpcn_u1582
phpcn_u1582 2017-07-05 10:26:13
0
3
2377

如何把前端的base64圖片上傳到阿里雲oss

phpcn_u1582
phpcn_u1582

全部回覆(3)
滿天的星座

先把資料decode_base64, 然後透過

  • 流式上傳就直接把解出來的內容直接上傳

  • 文件上傳,就儲存為臨時文件,再以傳統方式上傳

習慣沉默

你現在是獲取到了base64的圖片了嗎 如果是的話 那就調用oss對應的上傳接口不就好了 如果沒有獲取到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;
        }
女神的闺蜜爱上我

看這裡 -- http://www.jianshu.com/p/665d...

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!