AWSS3GetObjectRequest ifModifiedSince不工作

适用于 iOS 7+, 基于 Xcode 6.1 构建使用Amazon SDK AWSiOSSDKv2 2.0.12, iPhone 5s和iPad 2 上进行测试

我正在使用Amazon SDK for iOS从我的Amazon S3存储桶下载图像。 下载工作正常但我想使用ifModifiedSince属性仅检索自特定日期以来已修改的图像(请参阅http://docs.aws.amazon.com/AWSiOSSDK/latest/Classes/AWSS3GetObjectRequest.html#/ / api / name / ifModifiedSince )

但是,这不起作用。 即使我指定的ifModifiedSince日期晚于S3上文件的修改日期,也会返回该文件。

根据亚马逊文档: ifModifiedSince

仅在指定时间后修改了对象,否则返回该对象,否则返回304(未修改)。

所以我不确定我做错了什么,或者亚马逊在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 Mobile SDK。 它应该解决时间格式问题。