Uploading a video to Cloudflare Steam using Swift

Viewed 151

I am using Cloudflare stream to store user-uploaded videos. I make a POST call to the server and get back a link, in which I am trying to upload a video to Cloudflare using multi-part form-data. I have tried it with and without Alamofire.

Here is the code I am currently using:

let timestamp = NSDate().timeIntervalSince1970
        AF.upload(multipartFormData: { (multipartFormData) in
            multipartFormData.append(videoUrl, withName: "image", fileName: "\(timestamp).mp4", mimeType: "\(timestamp)/mp4")
        }, to: endPoint!  ).responseJSON { (response) in
            debugPrint(response)
        }

This is not working correctly. When looking at the Cloudflare documentation, it uses JS to do this:

const formData = new FormData();
        formData.append("file", video);
        const uploadResult = await fetch(oneTimeUploadUrl, {
          method: "POST",
          body: formData,
        });

I have tried making a POST call and putting the video data into the body. I am confused about what is going wrong.

1 Answers

Did you try to change the withName:"image" to withName:"file" ?

Related