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
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With