- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
为 iOS 7+ 构建,基于 Xcode 6.1,使用亚马逊 SDK AWSiOSSDKv2 2.0.12,测试 iPhone 5s 和 iPad 2
我正在使用适用于 iOS 的 Amazon SDK 从我的 Amazon S3 存储桶下载图像。下载工作正常,但我想使用 ifModifiedSince 属性仅检索自某个日期以来已修改的图像(参见 http://docs.aws.amazon.com/AWSiOSSDK/latest/Classes/AWSS3GetObjectRequest.html#//api/name/ifModifiedSince)
但是,这是行不通的。即使我指定的 ifModifiedSince 日期晚于 S3 上文件的修改日期,文件也会被返回。
根据亚马逊文档:ifModifiedSince -
Return the object only if it has been modified since the specified time, otherwise return a 304 (not modified).
所以我不确定是我做错了什么还是亚马逊的 SDK 有错误。
这是我的代码:
-(void)downloadPhotoWithName:(NSString*)name completed:(retrievedImage)completed {
NSFileManager *manager = [NSFileManager defaultManager];
NSArray *cachePaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cacheDirectory = [cachePaths firstObject];
NSString *filename = [NSString stringWithFormat:@"%@.jpg", name];
NSString *filePath = [cacheDirectory stringByAppendingPathComponent:filename];
AWSS3 *transferManager = [AWSS3 defaultS3];
AWSS3GetObjectRequest *profilePhoto = [[AWSS3GetObjectRequest alloc] init];
profilePhoto.bucket = S3BUCKETNAMEIMAGE;
profilePhoto.key = filename;
if ([manager fileExistsAtPath:filePath isDirectory:NULL]) {
NSDictionary *att = [manager attributesOfItemAtPath:filePath error:nil];
if (att) {
//Get the date of when the file was modified so we can request to retrieve
//the file only if it was modified SINCE that date
NSDate *modifiedDate = [att objectForKey:NSFileModificationDate];
if (modifiedDate) {
profilePhoto.ifModifiedSince = modifiedDate;
}
}
}
[[transferManager getObject:profilePhoto] continueWithBlock:^id(BFTask *task) {
//If it was working we should get a 304 not the image file
if (task.result) {
AWSS3GetObjectOutput *output = (AWSS3GetObjectOutput*)task.result;
NSData *imageData = (NSData*)output.body;
if (imageData) {
NSDictionary* attr = [NSDictionary dictionaryWithObjectsAndKeys:output.lastModified, NSFileModificationDate, NULL];
//The log confirms that the date I am passing for ifModifiedSince is LATER THAN
//the last modified date of the file on S3
//but the the image file is returned anyway.. is it a problem with Amazon ?
NSLog(@"output.lastModified: %@\nmodifiedDate: %@", output.lastModified, profilePhoto.ifModifiedSince);
if ([manager createFileAtPath:filePath contents:imageData attributes:attr]) {
completed(imageData);
}
else {
NSLog(@"Could not save image to disk for some reason");
completed(nil);
}
}
else {
completed(nil);
}
}
else if (task.error) {
NSLog(@"DownloadPhotoError: %@", task.error);
completed(nil);
}
return nil;
}];
}
最佳答案
我们发布了适用于 iOS 2.0.14 的 AWS 移动开发工具包。它应该解决时间格式问题。
关于ios - AWSS3GetObjectRequest ifModifiedSince 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27190654/
我使用他们的 SDK 从 S3 下载图像,如下所示: s3Client.getObject(new GetObjectRequest("a24images", s3FileURLString), fi
关闭。这个问题需要更多focused 。目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 已关闭 8 年前。 Improve this q
作为问题,我正在尝试获取 Amazon S3 存储库中的文件。我收到来自亚马逊的消息“InvalidAccessKeyId” The AWS Access Key Id you provided do
我正在尝试读取一个大的AWS S3压缩对象(gz)。我不想读取整个对象,想部分读取它,以便我可以并行处理未压缩的数据我正在使用带有“Range” header 的 GetObjectRequest 来
我正在使用 AWS CPP SDK ( https://github.com/aws/aws-iot-device-sdk-cpp ) 在小型 Linux 系统(只有 32 MB RAM)上从 S3
我是一名优秀的程序员,十分优秀!