gpt4 book ai didi

ios - AWSS3GetObjectRequest ifModifiedSince 不工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:02:52 26 4
gpt4 key购买 nike

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/

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