ios - 视频,上传到S3存储桶,不在iOS应用程序中通过url播放

标签 ios swift amazon-web-services post

我通过对 s3 服务的发布请求将视频和图像上传到 S3 存储桶上(不使用 AWS SDK)。图片和视频已成功上传。但视频无法从其网址播放。

下面是控制台上打印的错误:

错误域=NSURLErrorDomain代码=-999“已取消”UserInfo={NSErrorFailingURLStringKey=https://s3url }

以下是我正在使用的多部分请求的代码:

    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
        }
    }

最佳答案

原因是上传视频时,未设置视频的内容类型,导致视频无法播放。在form-data和Policy中设置Content-Type,视频上传并播放成功。

关于ios - 视频,上传到S3存储桶,不在iOS应用程序中通过url播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59282815/

相关文章:

html - 将 HTML 页面转换为 iOS View

ios - 由于未捕获的异常 'NSGenericException' 而终止应用程序,原因 : 'Unable to activate constraint with anchors

ios - 如何设置视频的 UIImagePickerController 方向?

ios - 在 viewDidLoad 之前编写 init 方法将模型传递给 View Controller

node.js - AWS DynamoDb 中出现 'Query condition missed key schema element' 的原因是什么?

amazon-web-services - 适用于 cloudformation 的最小权限 AWS IAM 策略

ios - 使用带 HTTPS 的 NSURLConnection 发送 POST

ios - 无法将类型 'UINavigationController' 的值转换为 'jacrs_ios.TopViewController'

arrays - 为什么数组不符合 Equatable,而它的项在 Swift 中是 Equatable 的?

amazon-web-services - 部署在 Amazon s3 上的 Angular 2 应用程序出现 404 错误