diff --git a/packages/uni-api/src/protocols/file/getFileInfo.ts b/packages/uni-api/src/protocols/file/getFileInfo.ts index 4556e4e3c6d468cb813a8ba2d6310dc8acd83ee3..e4aec8d883fc92a87c0f1281b80a0274e1d25205 100644 --- a/packages/uni-api/src/protocols/file/getFileInfo.ts +++ b/packages/uni-api/src/protocols/file/getFileInfo.ts @@ -1,6 +1,16 @@ +import { getRealPath } from '@dcloudio/uni-platform' + export const API_GET_FILE_INFO = 'getFileInfo' export type API_TYPE_GET_FILE_INFO = typeof uni.getFileInfo +export const GetFileInfoOptions: ApiOptions = { + formatArgs: { + filePath(filePath, params) { + params.filePath = getRealPath(filePath) + }, + }, +} + export const GetFileInfoProtocol: ApiProtocol = { filePath: { type: String, diff --git a/packages/uni-api/src/protocols/file/openDocument.ts b/packages/uni-api/src/protocols/file/openDocument.ts index be37ae790ebb91973436636bcc11a5e1881304bc..18387045c334f4aaf5516f1d3af0c72f1d038677 100644 --- a/packages/uni-api/src/protocols/file/openDocument.ts +++ b/packages/uni-api/src/protocols/file/openDocument.ts @@ -1,6 +1,16 @@ +import { getRealPath } from '@dcloudio/uni-platform' + export const API_OPEN_DOCUMENT = 'openDocument' export type API_TYPE_OPEN_DOCUMENT = typeof uni.openDocument +export const OpenDocumentOptions: ApiOptions = { + formatArgs: { + filePath(filePath, params) { + params.filePath = getRealPath(filePath) + }, + }, +} + export const OpenDocumentProtocol: ApiProtocol = { filePath: { type: String, diff --git a/packages/uni-api/src/protocols/network/uploadFile.ts b/packages/uni-api/src/protocols/network/uploadFile.ts index 89d8d1b5e3b9a649a995c2ef94e39d09979e7dc2..d4e2dc0219bd7610e92bee499785a55f1931e1df 100644 --- a/packages/uni-api/src/protocols/network/uploadFile.ts +++ b/packages/uni-api/src/protocols/network/uploadFile.ts @@ -1,7 +1,14 @@ +import { getRealPath } from '@dcloudio/uni-platform' + export const API_UPLOAD_FILE = 'uploadFile' export type API_TYPE_UPLOAD_FILE = typeof uni.uploadFile export const UploadFileOptions: ApiOptions = { formatArgs: { + filePath(filePath, params) { + if (filePath) { + params.filePath = getRealPath(filePath) + } + }, header(value: Record, params: Record) { params.header = value || {} }, diff --git a/packages/uni-h5/dist/uni-h5.esm.js b/packages/uni-h5/dist/uni-h5.esm.js index 1093468a1aa9ee4cdd9ba535bbb4cc42947d466b..3750df2cfc05230e556448b940d92d422cf8df47 100644 --- a/packages/uni-h5/dist/uni-h5.esm.js +++ b/packages/uni-h5/dist/uni-h5.esm.js @@ -4550,6 +4550,13 @@ const API_REMOVE_STORAGE = "removeStorage"; const RemoveStorageProtocol = GetStorageProtocol; const RemoveStorageSyncProtocol = GetStorageSyncProtocol; const API_GET_FILE_INFO = "getFileInfo"; +const GetFileInfoOptions = { + formatArgs: { + filePath(filePath, params) { + params.filePath = getRealPath(filePath); + } + } +}; const GetFileInfoProtocol = { filePath: { type: String, @@ -4557,6 +4564,13 @@ const GetFileInfoProtocol = { } }; const API_OPEN_DOCUMENT = "openDocument"; +const OpenDocumentOptions = { + formatArgs: { + filePath(filePath, params) { + params.filePath = getRealPath(filePath); + } + } +}; const OpenDocumentProtocol = { filePath: { type: String, @@ -4797,6 +4811,11 @@ const DownloadFileProtocol = { const API_UPLOAD_FILE = "uploadFile"; const UploadFileOptions = { formatArgs: { + filePath(filePath, params) { + if (filePath) { + params.filePath = getRealPath(filePath); + } + }, header(value, params) { params.header = value || {}; }, @@ -11078,11 +11097,11 @@ const getFileInfo = defineAsyncApi(API_GET_FILE_INFO, ({filePath}, {resolve, rej }).catch((err) => { reject(String(err)); }); -}, GetFileInfoProtocol); +}, GetFileInfoProtocol, GetFileInfoOptions); const openDocument = defineAsyncApi(API_OPEN_DOCUMENT, ({filePath}, {resolve}) => { window.open(filePath); return resolve(); -}, OpenDocumentProtocol); +}, OpenDocumentProtocol, OpenDocumentOptions); function getServiceAddress() { return window.location.protocol + "//" + window.location.host; } diff --git a/packages/uni-h5/src/service/api/file/getFileInfo.ts b/packages/uni-h5/src/service/api/file/getFileInfo.ts index a5d0f44100beb10c68e523a7be510c1d193c098a..04143ac6cec5eb312b4a302a1a2219f45ed123af 100644 --- a/packages/uni-h5/src/service/api/file/getFileInfo.ts +++ b/packages/uni-h5/src/service/api/file/getFileInfo.ts @@ -3,6 +3,7 @@ import { API_GET_FILE_INFO, API_TYPE_GET_FILE_INFO, GetFileInfoProtocol, + GetFileInfoOptions, } from '@dcloudio/uni-api' import { urlToFile } from '../../../helpers/file' @@ -20,5 +21,6 @@ export const getFileInfo = defineAsyncApi( reject(String(err)) }) }, - GetFileInfoProtocol + GetFileInfoProtocol, + GetFileInfoOptions ) diff --git a/packages/uni-h5/src/service/api/file/openDocument.ts b/packages/uni-h5/src/service/api/file/openDocument.ts index ccd2195cde111f0f536c56479087b11ac2fb2abe..1ebe54a7dc517c79fb9026f7be4f76c2653f4f68 100644 --- a/packages/uni-h5/src/service/api/file/openDocument.ts +++ b/packages/uni-h5/src/service/api/file/openDocument.ts @@ -3,6 +3,7 @@ import { API_TYPE_OPEN_DOCUMENT, defineAsyncApi, OpenDocumentProtocol, + OpenDocumentOptions, } from '@dcloudio/uni-api' export const openDocument = defineAsyncApi( @@ -11,5 +12,6 @@ export const openDocument = defineAsyncApi( window.open(filePath) return resolve() }, - OpenDocumentProtocol + OpenDocumentProtocol, + OpenDocumentOptions )