简体   繁体   English

使用适用于iOS的Amazon S3 Transfer Utility设置元数据

[英]Set metadata using Amazon S3 Transfer Utility for iOS

I can't find a way to set metadata using this library: Amazon S3 Transfer Utility for iOS 我找不到使用此库设置元数据的方法: 适用于iOS的Amazon S3 Transfer Utility

Is there a way to achieve this? 有没有办法做到这一点?

You can use - setValue:forRequestParameter: on AWSS3TransferUtilityExpression to add metadata. 您可以在AWSS3TransferUtilityExpression上使用AWSS3TransferUtilityExpression - setValue:forRequestParameter:添加元数据。

Note Amazon S3 stores user-defined metadata in lowercase. 注意Amazon S3以小写形式存储用户定义的元数据。 Each name, value pair must conform to US-ASCII. 每个名称/值对必须符合US-ASCII。

You can assign user-defined metadata to an object. 您可以将用户定义的元数据分配给对象。 User-defined metadata must begin with the prefix "x-amz-meta-", otherwise Amazon S3 will not set the key value pair as you define it. 用户定义的元数据必须以前缀“ x-amz-meta-”开头,否则,Amazon S3将不会在您定义键值对时对其进行设置。 You define custom metadata by adding a name that you choose to the x-amz-meta- key. 您可以通过在x-amz-meta-key中添加您选择的名称来定义自定义元数据。 This creates a custom key. 这将创建一个自定义密钥。 For example, if you add the custom name alt-name, the metadata key would be x-amz-meta-alt-name. 例如,如果添加自定义名称alt-name,则元数据键将为x-amz-meta-alt-name。

You can refer this link : https://docs.aws.amazon.com/AmazonS3/latest/user-guide/add-object-metadata.html#add-object-metadata-user-defined 您可以参考以下链接: https : //docs.aws.amazon.com/AmazonS3/latest/user-guide/add-object-metadata.html#add-object-metadata-user-defined

  var uploadCompletion: AWSS3TransferUtilityUploadCompletionHandlerBlock?
    uploadCompletion = { (uploadTask, error) in
        if error == nil {
            completion(nil)
        } else {
            completion(error)
        }
    }

    let expression = AWSS3TransferUtilityUploadExpression()
//YOUR METADATA HERE
    expression.setValue("value", forRequestParameter: "x-amz-meta-yourkeyhere")

    let transferUtility = AWSS3TransferUtility.default()
    transferUtility.uploadData(data,
                               bucket: s3BucketName,
                               key: key,
                               contentType: "image/png",
                               expression: expression,
                               completionHandler: uploadCompletion)

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

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