From dcdf12a15b19f458aeb16aee536bc1743278ebed Mon Sep 17 00:00:00 2001 From: Luk Lu Date: Wed, 16 Sep 2020 19:33:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=20pickupFile2Cloud=20?= =?UTF-8?q?=E7=9A=84=E4=BA=91=E6=96=87=E4=BB=B6=E5=91=BD=E5=90=8D=20cloudP?= =?UTF-8?q?ath=EF=BC=8C=E5=8C=85=E5=90=AB=E8=A7=86=E9=A2=91=E9=95=BF?= =?UTF-8?q?=E5=BA=A6=EF=BC=8C=E5=8F=96=E6=B6=88=E7=BB=99=20*.mov=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20.mp4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- unitool/index.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/unitool/index.js b/unitool/index.js index 739d815..ff32d5d 100644 --- a/unitool/index.js +++ b/unitool/index.js @@ -91,25 +91,32 @@ module.exports = { // #ifndef H5 // let [errorGetImageInfo, { path, width, height, orientation, type }] = await uni.getImageInfo({ src: filePath }) // cloudPath = path // 完整路径,包含后缀名。形如 file:///var/mobile/Containers/Data/Application/55A76332-44F5-4D5F-A9F6-3F857D584883/Documents/Pandora/apps/D064A425A8BEC13F9D8F741B98B37BC5/doc/uniapp_temp_1598593902955/compressed/1598593925815.png - cloudPath = `APP_${systemInfo.platform}_${filePath}` // 在 iOS 上是 "_doc/uniapp_temp_1598593902955/compressed/1598593925815.png", 有时还包含从 file:/// 开始的完整路径名 + cloudPath = `APP_${systemInfo.platform}__${filePath}` // 在 iOS 上是 "_doc/uniapp_temp_1598593902955/compressed/1598593925815.png", 有时还包含从 file:/// 开始的完整路径名 // #endif // #ifdef H5 - cloudPath = `H5_${systemInfo.platform}_${systemInfo.browser}_${tempFiles[0].name}` // name is available in H5 only. 只包含文件名和后缀名,不包含路径。 + cloudPath = `H5_${systemInfo.platform}_${systemInfo.browser}__${tempFiles[0].name}` // name is available in H5 only. 只包含文件名和后缀名,不包含路径。 // #endif } else if (mediaType === 'video') { let [errorChoose, { tempFilePath, tempFile, duration, size, width, height, name }] = await uni.chooseVideo({ sourceType, maxDuration }) // uni.showModal({ title: 'tempFilePath=' + tempFilePath }) filePath = tempFilePath // 在 iOS 上形如 "file:///var/mobile/Containers/Data/Application/55A76332-44F5-4D5F-A9F6-3F857D584883/Documents/Pandora/apps/26B43CD2F587D37FC6799108434A6F84/doc/uniapp_temp_1598596171580/gallery/IMG_3082.MOV" // #ifndef H5 - cloudPath = `APP_${systemInfo.platform}_${filePath}.mp4` // iOS 上测试,filePath 为 *.MOV,而阿里云只允许 *.mp4 + cloudPath = `APP_${systemInfo.platform}_dur${duration}__${filePath}` // #endif // #ifdef H5 - cloudPath = `H5_${systemInfo.platform}_${systemInfo.browser}_${name}` // tempFile and name are H5 only + cloudPath = `H5_${systemInfo.platform}_${systemInfo.browser}_dur${duration}__${name}` // tempFile and name are H5 only // #endif + // iOS 上测试,filePath 为 *.MOV,而阿里云只允许 *.mp4, 所以添加 .mp4 后缀。参见 https://uniapp.dcloud.net.cn/uniCloud/storage?id=clouduploadfile + // 20200915测试,阿里云支持上传 *.mov 了。 + if (!/\.(mp4|mov)$/i.test(cloudPath)) cloudPath = cloudPath + '.mp4' } else { return { _state: 'UNKNOWN_MEDIA_TYPE' } } + if (process.env.NODE_ENV === 'development') { + cloudPath = 'dev_' + cloudPath + } + if (filePath) { uni.showLoading() const { fileID, requestId } = await uniCloud.uploadFile({ @@ -259,7 +266,8 @@ module.exports = { formatDate(date, format) { if (!(date instanceof Date)) { if (typeof date === 'string' && /^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\.\d\d\d$/.test(date)) { - date = date.replace(/-/g, '/') + // 这是从 typeorm 数据库得到的Date类型的值 + date = date.replace(/-/g, '/') // safari 不支持 yyyy-mm-dd,必须改成 yyyy/mm/dd } date = new Date(date) }