我正在尝试使用Swift 3将视频上传到Cloudinary(未签名上传),来自我确定知道的视频网址。 我试图获取本地URL的内容并将其转换为数据,然后上传数据。我收到一条消息:
Error Domain=com.cloudinary.error Code=400 "(null)" UserInfo={message=Invalid image file}
这是我的上传代码:
func approveFunc(){
let config = CLDConfiguration(cloudName: "xxxxx", apiKey: "xxxxxx")
let cloudinary = CLDCloudinary(configuration: config)
let params = CLDUploadRequestParams(params: ["resource_type": "video" as AnyObject])
var data: Data?
do{
data = try NSData(contentsOfFile: (self.videoURL.relativePath), options: NSData.ReadingOptions.alwaysMapped) as Data
} catch {
}
cloudinary.createUploader().upload(data: data!, uploadPreset: "fycdpm" , params: params, progress: nil, completionHandler: {(response, error) in
print("done")
print(response)
print(error)
})
}
我也尝试直接从文件url上传:
cloudinary.createUploader().upload(url: self.videoURL, uploadPreset: "fycdp7cm" , params: params, progress: nil, completionHandler: {(response, error) in
print("done")
print(response)
print(error)
})
得到了同样的错误
答案 0 :(得分:1)
似乎resource_type
没有传递给服务器,因此Cloudinary期望上传图像(默认值)和错误。
您是否尝试过以下操作?
let params = CLDUploadRequestParams().setResourceType(.video)
请参阅以下内容以供参考: https://github.com/cloudinary/cloudinary_ios/blob/master/CloudinaryTests/NetworkTests/UploaderTests.swift#L81-L104