UploadFileWorker.js
906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { uploadFile } from '@/utils/ossUploadFile/uploadFile.js'
export default class UploadFileWorker {
constructor() {}
async work(deviceId, data, ws) {
const { filePath } = data
if (!filePath) {
ws.send({ error: '文件路径不能为空', requestData: data })
return
}
try {
uni.$logger.info(`[UploadFileWorker] 开始上传文件: ${filePath}`)
const url = await uploadFile(filePath)
uni.$logger.info(`[UploadFileWorker] 上传成功: ${url}`)
ws.send({
code: 200,
msg: '上传成功',
data: {
url,
filePath
},
requestData: data
})
} catch (error) {
const msg = `上传失败: ${error.message || error}`
uni.$logger.error(`[UploadFileWorker] ${msg}`)
ws.send({
code: 500,
error: msg,
requestData: data
})
}
}
}