gpt4 book ai didi

ios - AWSS3 上传失败并出现错误

转载 作者:行者123 更新时间:2023-11-30 13:00:35 25 4
gpt4 key购买 nike

我想在亚马逊服务器上上传图像,但每次我尝试上传图像时,它都会在日志中显示错误

016-10-08 14:37:41.741 Vabo[3091:62598] AWSiOSSDK v2.4.10 [Debug] AWSURLSessionManager.m line:543 | -[AWSURLSessionManagerprintHTTPHeadersAndBodyForRequest:] Request body: 2016-10-08 14:38:44.171 Vabo[3091:62596] AWSiOSSDK v2.4.10 [Error] AWSURLSessionManager.m line:212 | -[AWSURLSessionManager URLSession:task:didCompleteWithError:]

Session task failed with error: Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={NSErrorFailingURLStringKey=https://s3.amazonaws.com/vabo/production/uploads/avatars/200/avatar.jpg, _kCFStreamErrorCodeKey=-2102, NSErrorFailingURLKey=https://s3.amazonaws.com/vabo/production/uploads/avatars/200/avatar.jpg, NSLocalizedDescription=The request timed out., _kCFStreamErrorDomainKey=4, NSUnderlyingError=0x7ca545a0 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102}}}

这是我用来上传图像的代码。

func fusumaImageSelected(image: UIImage) {
self.imageView.image = image


let fileName = NSProcessInfo.processInfo().globallyUniqueString.stringByAppendingString(".jpg")
let fileURL = NSURL(fileURLWithPath: NSTemporaryDirectory()).URLByAppendingPathComponent("upload").URLByAppendingPathComponent(fileName)
let filePath = fileURL.path!
let imageData = UIImageJPEGRepresentation(image, 0.5)
imageData!.writeToFile(filePath, atomically: true)



let putObjectRequest = AWSS3PutObjectRequest()
putObjectRequest.body = imageData
putObjectRequest.contentLength = NSNumber.init(long: (imageData?.length)!)
putObjectRequest.expires = NSDate().dateByAddingTimeInterval(3600);
putObjectRequest.contentType = "image/png"
putObjectRequest.key = "production/uploads/avatars/200/avatar.jpg"
putObjectRequest.bucket = Constants.S3BucketName

self.uploadProgessInLoading(putObjectRequest)
AWSS3.defaultS3().putObject(putObjectRequest).continueWithBlock{(task) -> AnyObject! in

if let error = task.error {
if error.domain == AWSS3TransferManagerErrorDomain as String {
if let errorCode = AWSS3TransferManagerErrorType(rawValue: error.code) {
switch (errorCode) {
case .Cancelled, .Paused:
dispatch_async(dispatch_get_main_queue(), { () -> Void in

})
break;

default:
print("upload() failed: [\(error)]")
break;
}
} else {
print("upload() failed: [\(error)]")
}
} else {
print("upload() failed: [\(error)]")
}
}

if let exception = task.exception {
print("upload() failed: [\(exception)]")
}

if task.result != nil {

}
return nil
}
}

最佳答案

为了解决这个问题,我必须添加桥接 header ,并且我为身份池使用了错误的区域。

关于ios - AWSS3 上传失败并出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39930982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com