改进 pickupFile2Cloud 的云文件命名 cloudPath,包含视频长度,取消给 *.mov 添加 .mp4
This commit is contained in:
		
							parent
							
								
									9d0b9e4a1a
								
							
						
					
					
						commit
						dcdf12a15b
					
				@ -91,25 +91,32 @@ module.exports = {
 | 
				
			|||||||
      // #ifndef H5
 | 
					      // #ifndef H5
 | 
				
			||||||
      // let [errorGetImageInfo, { path, width, height, orientation, type }] = await uni.getImageInfo({ src: filePath })
 | 
					      // 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 = 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
 | 
					      // #endif
 | 
				
			||||||
      // #ifdef H5
 | 
					      // #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
 | 
					      // #endif
 | 
				
			||||||
    } else if (mediaType === 'video') {
 | 
					    } else if (mediaType === 'video') {
 | 
				
			||||||
      let [errorChoose, { tempFilePath, tempFile, duration, size, width, height, name }] = await uni.chooseVideo({ sourceType, maxDuration })
 | 
					      let [errorChoose, { tempFilePath, tempFile, duration, size, width, height, name }] = await uni.chooseVideo({ sourceType, maxDuration })
 | 
				
			||||||
      //      uni.showModal({ title: 'tempFilePath=' + tempFilePath })
 | 
					      //      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"
 | 
					      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
 | 
					      // #ifndef H5
 | 
				
			||||||
      cloudPath = `APP_${systemInfo.platform}_${filePath}.mp4` // iOS 上测试,filePath 为 *.MOV,而阿里云只允许 *.mp4
 | 
					      cloudPath = `APP_${systemInfo.platform}_dur${duration}__${filePath}`
 | 
				
			||||||
      // #endif
 | 
					      // #endif
 | 
				
			||||||
      // #ifdef H5
 | 
					      // #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
 | 
					      // #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 {
 | 
					    } else {
 | 
				
			||||||
      return { _state: 'UNKNOWN_MEDIA_TYPE' }
 | 
					      return { _state: 'UNKNOWN_MEDIA_TYPE' }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (process.env.NODE_ENV === 'development') {
 | 
				
			||||||
 | 
					      cloudPath = 'dev_' + cloudPath
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (filePath) {
 | 
					    if (filePath) {
 | 
				
			||||||
      uni.showLoading()
 | 
					      uni.showLoading()
 | 
				
			||||||
      const { fileID, requestId } = await uniCloud.uploadFile({
 | 
					      const { fileID, requestId } = await uniCloud.uploadFile({
 | 
				
			||||||
@ -259,7 +266,8 @@ module.exports = {
 | 
				
			|||||||
  formatDate(date, format) {
 | 
					  formatDate(date, format) {
 | 
				
			||||||
    if (!(date instanceof Date)) {
 | 
					    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)) {
 | 
					      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)
 | 
					      date = new Date(date)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user