How to upload videos as a file directly to server using Alamofire 5?

56 Views Asked by At

I wish to upload a video file stored on the mobile device on which the app is downloaded, to a folder within my server (ran with PHP). I am trying to use Alamofire to do this, and it said in their documentation that I should NOT use multipart form data for this as it could be too slow/memory intensive. Instead, I am using, as was recommended in the Alamofire documentation, this code to upload the video file directly to the server:

AF.upload(videoURL, to: "[string of url of my server folder]")

Here, videoURL is the local url of the video (an mp4 file) on the phone. Now, as for the url to my server, if I just put in the the path to the folder, the return string I get just seems to scrape the HTML code of the web page that you get when you past in the link into a browser, and the file is not uploaded.

Then, if I write a path to a new file within the folder that doesn't already exist, the error message just says:

The requested URL was not found on this server.

Lastly, I have tried passing in the url of an already existing mp4 file with a video in the server folder, hoping that when I upload to this url, this video will then be replaced by my video file. However, what gets returned as a message from the server then is a very (very) long string (making Xcode very laggy) that I believe is some representation of the current video already in the file, and on the server the video has not been replaced.

So, I have tried these three different possibilities, but none of them seem to get the file uploaded to the server. Do you have any idea what the problem is? Do I need to do something server side, with PHP code, or is it fine as it is just trying to upload the video like this? According to what I could find in the documentation, this seems to me like it should be ok.

Link to documentation: https://github.com/Alamofire/Alamofire/blob/master/Documentation/Usage.md

0

There are 0 best solutions below