AWSS3GetObjectRequest ifModifiedSince not working

Creation for iOS 7+, Based on Xcode 6.1, Using the Amazon AWSiOSSDKv2 2.0.12 SDK, Testing on iPhone 5 and iPad 2

I upload images from my Amazon S3 bucket using the Amazon SDK for iOS. Downloading works fine, but I want to use the ifModifiedSince property to retrieve only images that have changed since a specific date (see http://docs.aws.amazon.com/AWSiOSSDK/latest/Classes/AWSS3GetObjectRequest.html#//api/ name / ifModifiedSince )

However, this does not work. Even when I specify the date of ifModifiedSince, which LATER THAN changed the file date to S3, the file is returned.

According to Amazon documentation: ifModifiedSince -

It returns an object only if it has been modified since the specified time, otherwise it returns 304 (not changed).

So I'm not sure if I am doing something wrong, or Amazon has an error in the SDK.

Here is my code:

-(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; }]; } 
+2
source share
1 answer

We have released the AWS Mobile SDK for iOS 2.0.14. It should take into account the problem of time formatting.

+3
source

Source: https://habr.com/ru/post/1266192/


All Articles