2
我使用V2 AWS iOS的SDK,以我的圖片上傳到服務器 我的代碼兩岸向前AWSS3TransferManagerUploadRequest得到
NSString * uniqueIdentifier = [[NSUUID UUID]UUIDString];
AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];
uploadRequest.bucket = @"my bucket";
uploadRequest.key = [NSString stringWithFormat:@"%@/images/%@.jpeg",objectId,uniqueIdentifier];
uploadRequest.ACL = AWSS3ObjectCannedACLPublicRead;
NSData * data = UIImageJPEGRepresentation(newImage, 0.8);
NSString *tmpDirectory = NSTemporaryDirectory();
NSString *tmpFile = [tmpDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpeg",uniqueIdentifier]];
NSLog(@"Temp File:%@", tmpFile);
[data writeToFile:tmpFile atomically:YES];
uploadRequest.body = [NSURL fileURLWithPath:tmpFile];
AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];
[[transferManager upload:uploadRequest] continueWithExecutor:[BFExecutor defaultExecutor]
withBlock:^id(BFTask *task) {
if (task.error != nil) {
NSLog(@"%s %@","Error uploading :", uploadRequest.key);
}else {
AWSS3TransferManagerUploadOutput * output = task.result;
NSLog(@"Upload completed %@",[output description]);
}
return nil;
}];
後,我將文件上傳到S3服務這裏是響應URL響應URL ? 我如何知道該圖像的網址? 我想通過數據庫把圖像放在一個對象中。
感謝