Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Video, uploaded on S3 bucket, not playing through url in iOS app

I am uploading the videos and images on S3 bucket through the post request to s3 service (without using AWS SDK). The images and videos are uploaded successfully. But the video is not playing from its url.

Below is the error that is printed on the console:

Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLStringKey=https://s3url}

Following is the code for the multipart request that I am using:

    Alamofire.upload(multipartFormData: { (multiPart) in
        if parameters != nil {
            for (key, value) in parameters! {
                multiPart.append((value as AnyObject).data(using: String.Encoding.utf8.rawValue)!, withName: key)
            }
        }
        print("mime type ==================>\(mimeType)")
        //mime type for video: "video/mp4"
        multiPart.append(file, withName: key, fileName: fileName, mimeType: mimeType)
    }, usingThreshold: 10000, to: url, method: .post, headers: headers) { (encodingResult) in
        switch encodingResult {
        case .success(let upload, _, _):
            upload.responseString(completionHandler: { (response) in
                print("response string")
                print(response)
            })
            upload.responseJSON { response in
                print(response)
                print(response.result.isSuccess)
            }
        case .failure(let error):
            failure(self.parseError(error: error))
            break
        }
    }
like image 737
S.V Avatar asked Dec 11 '19 09:12

S.V


1 Answers

The reason for this was that while uploading the video, the Content-Type for video was not setting due to which the video was not playing. Setting the Content-Type in form-data as well as in Policy, the video uploaded and played successfully.

like image 101
S.V Avatar answered Oct 21 '22 07:10

S.V