我正在尝试将视频文件上传到Amazon S3 我经常收到错误260:
上传视频时出错:错误 Domain = NSCocoaErrorDomain Code = 260“操作不能 完成。 (可可错误260。)
我读过亚马逊不支持资产库的地方 - 这是真的吗?如果是的话,你有什么建议 谢谢伊兰
func saveVideoToS3(){
var uploadRequest: AWSS3TransferManagerUploadRequest = AWSS3TransferManagerUploadRequest()
uploadRequest.bucket = "BucketName"
uploadRequest.key = "KeyText"
//Move video file to the application folder so it can be read
var savedVideoURLToBeUsed = NSUserDefaults.standardUserDefaults().objectForKey("ThisIsTheVideoIWantToUse") as! String
println("Video saved in Store: \(savedVideoURLToBeUsed)")
var url: NSURL = NSURL(fileURLWithPath: savedVideoURLToBeUsed)!
uploadRequest.body = url
//uploadRequest.body = NSURL(fileURLWithPath: "file:///\(url)")
println("URL: \(url)")
let transferManager: AWSS3TransferManager = AWSS3TransferManager.defaultS3TransferManager()
transferManager.upload(uploadRequest).continueWithExecutor(AWSExecutor.mainThreadExecutor(), withBlock: { (AWSTask) -> AnyObject! in
//Handle errors
if AWSTask.error != nil {
println("Error in uploading the video: \(AWSTask.error)")
if AWSTask.error.code == 1001 {
self.saveVideoToS3()
}
// Retrive information important for later downloading
} else {
println("Video upload successful..")
var uploadResult: AnyObject! = AWSTask.result
println("Upload result: \(uploadResult)")
//Delete file from the application folder
}
return nil
})
}
答案 0 :(得分:0)
Cocoa错误260是NSFileReadNoSuchFileError
,意味着您指定的路径无效(文件不在您说的位置),因此S3本身可能没有任何内容。发生这种情况有三件事让我想到:
.synchronize()
iOS8重大改变
另请注意,从iOS8开始,由于更改了应用程序如何使用其分配的沙箱,您无法将绝对URL保存到文件,因为下次打开应用程序时,它会有所不同。
从iOS 8开始,Documents和Library目录都没有 申请人捆绑的兄弟姐妹。
我正在使用两个快速便捷函数来编写缓存目录中的文件:
func cachePathWithFileName(fileName : String) -> String {
let cacheDirectoryPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! String
return cacheDirectoryPath.stringByAppendingPathComponent(fileName)
}
和文件目录:
func documentsPathWithFileName(fileName : String) -> String {
let documentsDirectoryPath = NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true)[0] as! String
return documentsDirectoryPath.stringByAppendingPathComponent(fileName)
}
希望这些提示有所帮助!