export const fileCOSUpload = (files) => { return new Promise(async (resolve, reject) => { const { data, status } = await axios.post(`xxxx`, { RequestId: keyGuid(), DataType: 2, UserName: Cookie.get('ti-user'), FileName:files.name}); // 获取到 Url 后,前端可以这样 ajax 上传 let xhr = new XMLHttpRequest(); // put上传 xhr.open('PUT', data.Response.UploadAddress, true);
// 请求头 xhr.setRequestHeader('X-TC-Titoken', Cookie.get('ti-token')); xhr.onload = (e) => { resolve(data.Response.FileId); }; xhr.onerror = (e) => { reject(null); }; xhr.send(files); // files 是要上传的文件对象 }) };