在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/云計算  網(wǎng)絡(luò)安全/ 阿里云oss如何上傳限制只能上傳圖片并實現(xiàn)多圖上傳?

阿里云oss如何上傳限制只能上傳圖片并實現(xiàn)多圖上傳?

doUpload(){
                let userId = localStorage.getItem('userId');
                let token = localStorage.getItem('token');
                const _this = this;
                axios({
                    url: "http://xxx.xxx.xxx.xxx/internal/oss/get_token",
                    method: 'GET',
                    headers: {'w-auth-token': token}
                }).then((res) => {
                    var client = new OSS.Wrapper({
                        accessKeyId: res.data.accessKeyId,
                        accessKeySecret: res.data.accessKeySecret,
                        stsToken: res.data.securityToken,
                        region: _this.region,
                        bucket: _this.bucket
                    });
                    const files = document.getElementById(_this.name);
                    if (files.files) {
                        const fileLen = document.getElementById(_this.name).files;
                        for (let i = 0; i < fileLen.length; i++) {
                            const file = fileLen[i];
                            var date = new Date();
                            let path="merchant/"+userId+"/"+date.getFullYear()+(date.getMonth()+1)+date.getDate()+date.getHours()+date.getMinutes()+date.getSeconds()+date.getMilliseconds()+ '.' + file.name.split('.').pop();
                            client.multipartUpload(path, file,{
                                progress: function* (percentage, cpt) {
                                    // 上傳進度
                                    _this.uploadImg.percentage = percentage*100+'%';
                                    console.log(_this.uploadImg.percentage);
                                }
                            }).then((results) => {
                                _this.uploadImg.url=results.url;
                                _this.uploadImg.name=results.name;
                                _this.uploadImg.status=true;
                                _this.show=true;
                                console.log(results.url);
                                console.log(results.name);
                            }).catch((err) => {
                                this.$Message.error('上傳圖片失敗,請重試!');
                            });
                        }
                    }else{
                        this.uploadImg.status=true;
                        this.uploadImg.url=this.src;
                    }
                });
            },

目前是參考網(wǎng)上大神寫的代碼,用的分片上傳,想問下各位大神如何限制只能上傳圖片,就是選擇文件的時候只顯示圖片格式的,以及如何多圖同時上傳,并且有地方可以設(shè)置上傳的圖片大小

回答
編輯回答
孤慣

<input accept="image/jpeg,image/jpg,image/png" multiple="multiple"/> accept="image/jpeg,image/jpg,image/png" 限制上傳圖片類型為png/jepg

2017年4月2日 07:08
編輯回答
悶油瓶

oss可以設(shè)置Content-Type(MIME)決定上傳的格式 多圖同時上傳可以利用循環(huán)去做

2017年4月1日 01:15
編輯回答
奧特蛋

該方法本身就是支持多圖上傳的,只要在input type="file"中加multiplie屬性即可

2018年7月13日 23:18