From 4d308078fa9322d1b2ce4e566608225120d5d686 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 2 May 2025 20:59:30 +0800 Subject: [PATCH] =?UTF-8?q?reactor=EF=BC=9A=E3=80=90INFRA=E3=80=91?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0=20api=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=20directory=20=E5=8F=82=E6=95=B0=EF=BC=8C=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=20path=20=E5=8F=82=E6=95=B0=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8C=89=E7=85=A7=E6=97=A5=E6=9C=9F=E5=88=86?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E3=80=81=E6=96=87=E4=BB=B6=E5=90=8D=E4=B8=8D?= =?UTF-8?q?=E5=86=8D=E4=BD=BF=E7=94=A8=20sha256=20=E8=80=8C=E6=98=AF?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=88=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sheep/api/infra/file.js | 16 +++++++++------- .../s-uploader/choose-and-upload-file.js | 13 ++++++++----- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/sheep/api/infra/file.js b/sheep/api/infra/file.js index 05e03dcf..88355951 100644 --- a/sheep/api/infra/file.js +++ b/sheep/api/infra/file.js @@ -1,11 +1,9 @@ import { baseUrl, apiPath, tenantId } from '@/sheep/config'; -import request from '@/sheep/request'; +import request, { getAccessToken } from '@/sheep/request'; const FileApi = { // 上传文件 - uploadFile: (file) => { - // TODO 芋艿:访问令牌的接入; - const token = uni.getStorageSync('token'); + uploadFile: (file, directory) => { uni.showLoading({ title: '上传中', }); @@ -17,7 +15,10 @@ const FileApi = { header: { Accept: '*/*', 'tenant-id': tenantId, - // Authorization: 'Bearer test247', + Authorization: 'Bearer ' + getAccessToken(), + }, + formData: { + directory, }, success: (uploadFileRes) => { let result = JSON.parse(uploadFileRes.data); @@ -42,12 +43,13 @@ const FileApi = { }, // 获取文件预签名地址 - getFilePresignedUrl: (path) => { + getFilePresignedUrl: (name, directory) => { return request({ url: '/infra/file/presigned-url', method: 'GET', params: { - path, + name, + directory, }, }); }, diff --git a/sheep/components/s-uploader/choose-and-upload-file.js b/sheep/components/s-uploader/choose-and-upload-file.js index a7a64080..cea26266 100644 --- a/sheep/components/s-uploader/choose-and-upload-file.js +++ b/sheep/components/s-uploader/choose-and-upload-file.js @@ -175,7 +175,7 @@ function uploadCloudFiles(files, max = 5, onUploadProgress) { }); } -function uploadFilesFromPath(path) { +function uploadFilesFromPath(path, directory) { // 目的:用于微信小程序,选择图片时,只有 path return uploadFiles( Promise.resolve({ @@ -187,11 +187,13 @@ function uploadFilesFromPath(path) { }, ], }), - {}, + { + directory, + }, ); } -async function uploadFiles(choosePromise, { onChooseFile, onUploadProgress }) { +async function uploadFiles(choosePromise, { onChooseFile, onUploadProgress, directory }) { // 获取选择的文件 const res = await choosePromise; // 处理文件选择回调 @@ -212,7 +214,7 @@ async function uploadFiles(choosePromise, { onChooseFile, onUploadProgress }) { const uploadPromises = files.map(async (file) => { try { // 1.1 获取文件预签名地址 - const { data: presignedInfo } = await FileApi.getFilePresignedUrl(file.name); + const { data: presignedInfo } = await FileApi.getFilePresignedUrl(file.name, directory); // 1.2 获取二进制文件对象 const fileBuffer = await readFile(file); @@ -260,6 +262,7 @@ async function uploadFiles(choosePromise, { onChooseFile, onUploadProgress }) { function chooseAndUploadFile( opts = { type: 'all', + directory: undefined, }, ) { if (opts.type === 'image') { @@ -279,7 +282,7 @@ function createFile(vo, file) { const fileVo = { configId: vo.configId, url: vo.url, - path: file.name, + path: vo.path, name: file.name, type: file.fileType, size: file.size,