[英]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.