在Swift中使用iOS AWS开发工具包检查Amazon S3文件的元数据 [英] Checking metadata of Amazon S3 file using iOS AWS SDK in Swift

查看:174
本文介绍了在Swift中使用iOS AWS开发工具包检查Amazon S3文件的元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AWS iOS SDK v2和Swift 1.2.

I am using the AWS iOS SDK v2, and Swift 1.2.

我正在将我的应用程序的app.json文件存储在S3上,并希望在启动时对其进行检查,以查看自上次运行以来是否已对其进行更新.根据研究,仅对对象执行HEAD请求应返回"Last-Modified"属性,然后可以将其与前一个属性进行比较.

I am storing my app's app.json file on S3 and want to check it at launch to see if it's been updated since the last run. According to research, simply doing a HEAD request on the object should return the "Last-Modified" attribute which can then be compared to the previous.

问题在于,对Object进行HEAD请求似乎并没有得到很好的记录.我有以下内容:

The problem is that doing a HEAD request on an Object doesn't really seem to be well documented. I've got the following:

var metaDataRequest = AWSS3HeadObjectRequest()
metaDataRequest.bucket = S3BucketName
metaDataRequest.key = S3AppJSONKey

这似乎是一个不错的开始,但是我找不到执行请求的方法. AWSS3TransferManager具有download()方法,但是该方法需要AWSS3TransferManagerDownloadRequest类型,而AWSS3HeadObjectRequest无法强制转换为该类型.

This seems like a decent start, however I cannot find a way to execute the request. The AWSS3TransferManager has a download() method, but the method requires an AWSS3TransferManagerDownloadRequest type, which an AWSS3HeadObjectRequest cannot be cast as.

不知道从这里去哪里,只需要在SDK外部进行请求即可.但是,我确实想尽可能多地利用SDK,因此,如果可能的话,我很想知道怎么做.

Not sure where to go from here, short of just doing the request outside of the SDK. I did, however, want to leverage as much of the SDK as possible, so if this is possible I would love to know how.

推荐答案

您需要调用AWSS3的headobject方法

You need to call headobject method of AWSS3

     var request = AWSS3HeadObjectRequest()

    request.bucket = "flkasdhflhad"
    request.key = "hfsdahfjkhadjkshf"

   request.ifModifiedSince = NSDate()


  var s3 = AWSS3.defaultS3()

    s3.headObject(request) { ( output1 : AWSS3HeadObjectOutput?, error : NSError?) -> Void in
   print( output1?.description())
    }

如果您的对象是从指定日期修改的,则它将返回u该对象,否则将返回u状态代码304.

if your object is modified from specified date then it will return u the object otherwise it will return u the status code 304.

这篇关于在Swift中使用iOS AWS开发工具包检查Amazon S3文件的元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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