简体   繁体   English

视频从iOS设备上传为图片,如何正确上传

[英]Video is uploaded as an image from iOS device, how to upload properly

I have an app that gets the images/videos from the mobile gallery, then uploads one of them to a server, here are the steps i take, which works fine on Android:我有一个应用程序可以从移动图库中获取图像/视频,然后将其中一个上传到服务器,这是我采取的步骤,在 Android 上运行良好:

1-get data from mobile storage: 1-从移动存储中获取数据:

MediaLibrary.getAssetsAsync({
  first: 20,
  mediaType: [MediaLibrary.MediaType.video, MediaLibrary.MediaType.photo]
})

2-upload to server: 2-上传到服务器:

formData.append('images[]', {
    uri: localUri,  
    name: isVideo ? 'untitled.mp4'  : 'untitled',//for testing
    type: isVideo ? 'video/mp4' : 'image/jpeg'
})

axios.post(`url`, formData, {headers: headers,timeout:999999})

The problem is videos are uploaded as an image (only the first frame of the video), while it gets uploaded successfully on Android, the problem is only present on iOS.问题是视频是作为图像上传的(只有视频的第一帧),虽然它在 Android 上成功上传,但问题只存在于 iOS。

The uri of the retrieved files is as follows: assets-library://asset/asset.MP4?id=xxx&ext=MP4检索到的文件uri如下: assets-library://asset/asset.MP4?id=xxx&ext=MP4

Quick notes:快速笔记:

1 - the video is played fine locally using the <Video> component from Expo 1 - 使用 Expo 的<Video>组件在本地正常播放<Video>

2 - i tried using the CameraRoll API, but it gives the same results, and is a little buggy 2 - 我尝试使用CameraRoll API,但它给出了相同的结果,并且有点问题

any help would be appreciated任何帮助,将不胜感激

You can update to expo SDK 36 and you will be able to solve this problem by using localUri returned by MediaLibrary.getAssetInfoAsync您可以更新到 expo SDK 36,您将能够使用MediaLibrary.getAssetInfoAsync返回的localUri解决此问题

ex.前任。

// get asset id like B84E8479-475C-4727-A4A4-B77AA9980897/L0/001
const info = await MediaLibrary.getAssetInfoAsync(asset.id)
const uri = info.localUri // use this for upload

Reffer this comment on github.在 github 上引用此评论。 https://github.com/expo/expo/issues/3177#issuecomment-510096711 https://github.com/expo/expo/issues/3177#issuecomment-510096711

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM