提交 9e6ace2f authored 作者: 王鹏飞's avatar 王鹏飞

chore: 修改上传为本地上传

上级 3a51537f
import axios from 'axios' import axios from 'axios'
import md5 from 'blueimp-md5' import { getLocalFileChunk, uploadLocalFile } from '@/api/base'
import { getSignature, uploadFile } from '@/api/base'
export async function upload(blob: Blob | File) { export async function upload(file: Blob) {
let fileType = 'png' const response = await getLocalFileChunk({ file_name: 'abc', file_size: file.size })
if (blob instanceof File && blob.name) {
const matches = blob.name.match(/\.(\w+)$/)
if (matches) {
fileType = matches[1]
}
} else if (blob.type) {
const mimeType = blob.type.split('/').pop()
if (mimeType) {
fileType = mimeType
}
}
const key =
'upload/resource-center/' + md5(new Date().getTime() + Math.random().toString(36).slice(-8)) + '.' + fileType
const response: any = await getSignature()
const params = { const params = {
key, file,
host: response.host, file_name: response.data.detail.file_name,
OSSAccessKeyId: response.accessid, now_package_num: 1,
policy: response.policy, total_package_num: 1
signature: response.signature,
success_action_status: '200',
file: blob,
url: `${response.host}/${key}`,
} }
await uploadFile(params) const res = await uploadLocalFile(params)
return params.url
return res.data.detail.uri
} }
export async function uploadFileByUrl(url: string) { export async function uploadFileByUrl(url: string) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论