Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
base64Reader.onload = (e) => {
const urlData = e.target.result;
const base64 = urlData.split(",").pop();
const fileType = urlData
.split(";")
.shift()
.split(":")
.pop();
// base64转blob
const blob = toBlob(base64, fileType);
const conf = {
useCdnDomain: true,
region: qiniu.region[config.region], // 区域
};
const putExtra = {
fname: "",
params: {},
mimeType: [] || null,
};
const OSSName = getOSSName(file.name, namespace);
// 这里第一个参数的形式是blob
const imageObservable = qiniu.upload(blob, OSSName, token, putExtra, conf);
// 上传成功后回调
const complete = (response) => {
// console.log(response);
uploadFn = async () => {
let response = await API.getToken();
let { baseUrl, token } = response.data;
let files = this.refs.upload.files;
console.log(files);
// 是否是一张照片?
// 七牛
if (!this.imageVerify()) return;
let putExtra = {
fname: '',
params: {},
mimeType: ['image/png','image/jpeg','image/gif']
};
let config = {
region: qiniu.region.z0
};
let key = new Date().getTime() + files[0].name;
let observable = qiniu.upload(files[0], key, token, putExtra, config)
let observer = {
compelete: (res) => {
let imgUrl = baseUrl + '/' + res.key;
console.log(imgUrl);
this.props.successCb(imgUrl);
},
error: (err) => {
notification.error({
message: err
})
}
}
let response = await API.getToken()
let {baseUrl, token} = response.data
let files = this.refs.upload.files
// 校验图片
if (!this.imageVerify) return
var putExtra = {
fname: "",
params: {},
mimeType: ["image/png", "image/jpeg", "image/gif"]
};
var config = {
region: qiniu.region.z0
};
// 文件名
let key = new Date().getTime() + files[0].name;
var observable = qiniu.upload(files[0], key, token, putExtra, config)
var observer = {
next: (res) => {
// ...
},
error: (err) => {
notification.error({
message: err
})
},
complete: (res) => {
uplaodAction2 (res, file, key) {
const _this = this
const observable = qiniu.upload(file, key, this.token, {
fname: key,
mimeType: []
}, {
useCdnDomain: true,
region: qiniu.region.z2
})
observable.subscribe({
next (res) {
_this.$set(_this.fileList[_this.fileList.findIndex(item => item.key === key)], 'percent', parseInt(res.total.percent))
},
error (err) {
_this.$set(_this.fileList, _this.fileList.findIndex(item => item.key === key), {
..._this.fileList[_this.fileList.findIndex(item => item.key === key)],
status: 'error'
})
_this.fileList.splice(_this.fileList.findIndex(item => item.key === key), 1)
},
complete (res) {
_this.$set(_this.fileList, _this.fileList.findIndex(item => item.key === key), {
..._this.fileList[_this.fileList.findIndex(item => item.key === key)],