简体   繁体   English

在上传到 S3 的对象上设置`Content-Disposition`?

[英]Setting `Content-Disposition` on Object uploaded to S3?

I have a .NET Core project that uploads objects to an S3 bucket.我有一个将对象上传到 S3 存储桶的 .NET Core 项目。 I want to set the Content-Disposition so when the object is downloaded the name is what we want to be.我想设置Content-Disposition以便在下载对象时,名称就是我们想要的名称。 (Not necessarily relevant, but I don't want to change the name of the object as the "download name" I am after is not guaranteed to be unique within the bucket). (不一定相关,但我不想更改对象的名称,因为不能保证我所追求的“下载名称”在存储桶中是唯一的)。

This is what I am trying:这就是我正在尝试的:

var fileTransferUtilityRequest = new TransferUtilityUploadRequest
{
    BucketName = "my-bucket", 
    FilePath = "/tmp/54a0f73d-65ea-4719-8227-b67209c15c9f.zip",
    PartSize = 6291456, // 6 MB.
    Key = "54a0f73d-65ea-4719-8227-b67209c15c9f.zip"
};

fileTransferUtilityRequest.Metadata.Add("Content-Disposition", "attachment; filename=\"human-name.zip\"");

await transferUtility.UploadAsync(fileTransferUtilityRequest, cancellationToken);

What it ends up doing is adding meta-data to the object with the key x-amz-meta-content-disposition and the value I set via code.它最终做的是使用键x-amz-meta-content-disposition和我通过代码设置的值向对象添加元数据。

Is there a way to set the Content-Disposition key during upload that I am missing?有没有办法在我丢失的上传过程中设置Content-Disposition键?

You can set the ContentDisposition in the Headers of the TransferUtilityUploadRequest您可以在TransferUtilityUploadRequest的 Headers 中设置ContentDisposition

var fileTransferUtilityRequest = new TransferUtilityUploadRequest
{
    BucketName = "my-bucket", 
    FilePath = "/tmp/54a0f73d-65ea-4719-8227-b67209c15c9f.zip",
    PartSize = 6291456, // 6 MB.
    Key = "54a0f73d-65ea-4719-8227-b67209c15c9f.zip"
};

fileTransferUtilityRequest.Headers.ContentDisposition = "attachment; filename=file-name.pdf";

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

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