allow pickupFile2Cloud for all file types
This commit is contained in:
parent
adb2a96287
commit
74826d0ac6
34
unitool.js
34
unitool.js
@ -342,10 +342,7 @@ export default {
|
||||
|
||||
let filePath,
|
||||
cloudPath,
|
||||
systemInfo = uni
|
||||
.getSystemInfoSync()
|
||||
.system.toLowerCase()
|
||||
.replace(/\s+/g, '')
|
||||
osName = uni.getSystemInfoSync().osName
|
||||
if (mediaType === 'image') {
|
||||
let [errorChoose, { tempFilePaths, tempFiles } = {}] = await uni.chooseImage({ count, sizeType, sourceType })
|
||||
// uni.showModal({ title: 'tempFilePaths[0]=' + tempFilePaths[0] })
|
||||
@ -353,37 +350,44 @@ export default {
|
||||
// #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}__${filePath}` // 在 iOS 上是 "_doc/uniapp_temp_1598593902955/compressed/1598593925815.png", 有时还包含从 file:/// 开始的完整路径名
|
||||
cloudPath = `APP_${osName}__${filePath}` // 在 iOS 上是 "_doc/uniapp_temp_1598593902955/compressed/1598593925815.png", 有时还包含从 file:/// 开始的完整路径名
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
cloudPath = `H5_${systemInfo}_${this.parse_ua_to_browser()}__${tempFiles[0].name}` // name is available in H5 only. 只包含文件名和后缀名,不包含路径。
|
||||
cloudPath = `H5_${osName}_${this.parse_ua_to_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}_dur${duration}__${filePath}`
|
||||
cloudPath = `APP_${osName}_dur${duration}__${filePath}`
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
cloudPath = `H5_${systemInfo}_${this.parse_ua_to_browser()}_dur${duration}__${name}` // tempFile and name are H5 only
|
||||
cloudPath = `H5_${osName}_${this.parse_ua_to_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: 'CLIENT_FAIL_UNKNOWN_MEDIA_TYPE' }
|
||||
let { errMsg, tempFilePaths, tempFiles } = await uniCloud.chooseAndUploadFile({
|
||||
type: 'all',
|
||||
count: 1,
|
||||
// extention: [],
|
||||
// onChooseFile: ({ errMsg, tempFilePaths, tempFiles }) => { },
|
||||
// onUploadProgress: ({ index, loaded, total, tempFilePath, tempFile }) => { }
|
||||
})
|
||||
if (errMsg === 'chooseAndUploadFile:ok') {
|
||||
return { _state: 'SUCCESS', fileUrl: tempFiles?.[0]?.url }
|
||||
} else {
|
||||
return { _state: 'CLIENT_FAIL_chooseAndUploadFile' }
|
||||
}
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
cloudPath = 'dev_' + cloudPath
|
||||
}
|
||||
|
||||
if (filePath) {
|
||||
uni.showLoading()
|
||||
const { fileID, requestId } = await uniCloud.uploadFile({
|
||||
filePath: filePath,
|
||||
cloudPath: cloudPath, // 关键是要具有文件格式后缀名,这样可以保持阿里云下载链接也用这个后缀名。
|
||||
cloudPath: process.env.NODE_ENV !== 'production' ? 'dev_' + cloudPath : cloudPath, // 关键是要具有文件格式后缀名,这样可以保持阿里云下载链接也用这个后缀名。
|
||||
fileType: mediaType, // = image, video, audio
|
||||
onUploadProgress: function (progressEvent) {
|
||||
var percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total)
|
||||
@ -393,9 +397,11 @@ export default {
|
||||
|
||||
if (fileID) {
|
||||
return { _state: 'SUCCESS', fileUrl: fileID, requestId }
|
||||
} else {
|
||||
return { _state: 'CLIENT_WOBASE_FAIL_uploadFile' }
|
||||
}
|
||||
}
|
||||
return { _state: 'CLIENT_FAIL_CHOOSE_FILE' }
|
||||
return { _state: 'CLIENT_FAIL_chooseFile' }
|
||||
},
|
||||
|
||||
async pickupFile ({
|
||||
|
Loading…
Reference in New Issue
Block a user