繁体   English   中英

如何获取文件Amazon S3,AWS IOS SDK的上传日期

[英]How to get upload date of a file Amazon S3, AWS IOS SDK

我有一个包含文件的S3存储桶。 我可以在我的应用程序上成功下载并显示该文件。

但是我想知道如果文件是最新的或没有。 使用Firefox S3扩展,我可以看到在存储桶文件名中,文件大小和上传时间都保存到S3。 上传时间的一个例子是10/10/2012 11:35 PM

得到我使用的网址

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_async(queue, ^{

        // Set the content type so that the browser will treat the URL as an image.
        S3ResponseHeaderOverrides *override = [[S3ResponseHeaderOverrides alloc] init];
        override.contentType = @" ";

        // Request a pre-signed URL to picture that has been uplaoded.
        S3GetPreSignedURLRequest *gpsur = [[S3GetPreSignedURLRequest alloc] init];
        gpsur.key                     = _fileName;
        gpsur.bucket                  = [Constants pictureBucket];
        gpsur.expires                 = [NSDate dateWithTimeIntervalSinceNow:(NSTimeInterval) 3600]; // Added an hour's worth of seconds to the current time.
        gpsur.responseHeaderOverrides = override;

        // Get the URL
        NSError *error;
        NSURL *url = [self.s3 getPreSignedURL:gpsur error:&error];

如何在Amazon S3上获取文件的上传日期?

编辑答案::::

好的,谢谢回答以下方法,我可以得到日期

S3GetObjectMetadataRequest *getMetadataRequest = [[S3GetObjectMetadataRequest alloc] initWithKey:_fileName withBucket:[Constants pictureBucket]];
        S3GetObjectMetadataResponse *getMetadataResponse = [self.s3 getObjectMetadata:getMetadataRequest];

        NSString *fileLastModifiedDate = [[NSString alloc] init];
        fileLastModifiedDate = [NSString stringWithFormat:@"%@",getMetadataResponse.lastModified];
        NSLog(@"Last Modified date %@",fileLastModifiedDate);

您必须创建一个S3GetObjectMetadataRequest。

S3GetObjectMetadataRequest *getMetadataRequest = [[S3GetObjectMetadataRequest alloc] initWithKey:filePath withBucket:BUCKET_NAME];
S3GetObjectMetadataResponse *getMetadataResponse = [self getObjectMetadata:getMetadataRequest];

http://docs.amazonwebservices.com/AmazonS3/latest/dev/UsingMetadata.html

Mord Fustang,关于你答案中的代码,还有一件事。 在从响应中访问NSString对象之前,不需要分配NSString对象。

NSString *fileModifiedDate = getMetadataResponse.lastModified;
NSLog(@"Last Modified date %@", fileModifiedDate);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM