How to download video iOS
Hi — I am trying to add a feature to share a video from Cloudinary through the iOS Share sheet, so it can be stored in a user's camera roll (or uploaded to Facebook, whatever).
From what I can gather, in order to make this work, I need to download the video to a file and then hand a local file URL to Apple's UIActivityViewController API. What I can't figure out is how to download the Cloudinary .mp4 file to disk.
I've tried three methods and they all fail:
1) CLDDownloader.fetchImage()
Doesn't work, because I guess this is meant only for images, not videos. I get the following error:
Error Domain=com.cloudinary.error Code=-7001 "Failed creating an image from the received data." UserInfo={NSLocalizedFailureReason=Failed creating an image from the received data.}
2) URLSession.downloadTask(url)
For this, I get a delegate callback of -urlSession(_:task:didCompleteWithError:), with error 'nil', but no file was ever downloaded. If I inspect the network response from Cloudinary, I see a 200, but there was never any file downloaded
3) AVAssetDownloadURLSession.makeAssetDownloadTask()
This returns an error, and maybe expected, as I'm handing it an mp4 URL, and I believe it's meant for HLS:
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedDescription=The operation could not be completed, _NSURLErrorFailingURLSessionTaskErrorKey=BackgroundAVAssetDownloadTask <6CC11F75-FFA9-4A17-9F6D-DDED135EAB5A>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"BackgroundAVAssetDownloadTask <6CC11F75-FFA9-4A17-9F6D-DDED135EAB5A>.<1>"
), NSLocalizedFailureReason=An unknown error occurred (-16090)}
What am I missing?
Or is there some other means I should be using to share videos?
Thanks,
Alan
-
Official comment
Hi Kevin,
You can download your video by using the fl_attachment parameter in your URL like this https://res.cloudinary.com/demo/video/upload/fl_attachment/dog.mp4
When the user loads this URL, he will automatically download this video.
Regards,
Akshay
-
Hi Alan,
Thanks for reaching out.
I can see you already opened a ticket regarding this issue.
I will answer your question through this ticket.
Best,
Loic
0 -
so how can i download the video
0
Post is closed for comments.
Comments
3 comments