如何获取文件的上传日期Amazon S3,AWS IOS SDK [英] How to get upload date of a file Amazon S3, AWS IOS SDK

查看:903
本文介绍了如何获取文件的上传日期Amazon S3,AWS IOS SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个S3桶里面有文件。我可以在我的应用程序中成功下载并显示该文件。



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



获取url我使用



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

//设置内容类型,以便浏览器将URL视为图像
S3ResponseHeaderOverrides * override = [[S3ResponseHeaderOverrides alloc] init ];
override.contentType = @;

//请求已经被重新编码的图片的预先签名的URL
S3GetPreSignedURLRequest * gpsur = [[S3GetPreSignedURLRequest alloc] init];
gpsur.key = _fileName;
gpsur.bucket = [常量pictureBucket];
gpsur.expires = [NSDate dateWithTimeIntervalSinceNow:(NSTimeInterval)3600]; //添加了一小时的值当前时间的秒数
gpsur.responseHeaderOverrides = override;

//获取URL
NSError *错误;
NSURL * url = [self.s3 getPreSignedURL:gpsur错误:& error];

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



EDIT :::: ANSWER



可以通过以下方法回答我可以得到日期



  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(@上次修改日期%@,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


I have a S3 bucket with files in it. I can successfully download and display the file on my app.

However I want to learn that if the document is the latest or not. With Firefox S3 extension I can see that in bucket file name, file size and upload time are saved to S3. An example of upload time is 10/10/2012 11:35 PM

to get url I use

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];

How can I get upload date of a file on Amazon S3?

EDIT::::ANSWER

OK thanks to answer with following method I can get the date

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);

解决方案

You have to make a S3GetObjectMetadataRequest.

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

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

这篇关于如何获取文件的上传日期Amazon S3,AWS IOS SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆