Disposition 属性创建/更新谷歌云存储对象元数据时,它是添加一个新属性而不是更新现有的 Content-Disposition。请参见下图。
我的目标是在下载对象时提供不同的名称。当我手动更新 Content-Disposition 时,它按预期工作。
我正在使用 .NET 客户端库,下面是代码
string fileNameWithExt = "filename.txt";
using (var stream = file.InputStream)
{
var obj = new Google.Apis.Storage.v1.Data.Object
{
Bucket = bucketName,
Name = fileName,
ContentType = "application/octet-stream",
Metadata = new Dictionary<string, string>
{
{ "Content-Disposition", $"attachment; filename={fileNameWithExt}" }
}
};
var gcsObject = storage.UploadObject(obj, stream);
var patchObject = new Google.Apis.Storage.v1.Data.Object
{
Bucket = bucketName,
Name = fileName,
//ContentType = "text/plain",
Metadata = new Dictionary<string, string>
{
{ "Content-Disposition", $"attachment; filename={fileNameWithExt}" }
}
};
storage.PatchObject(patchObject);
繁花不似锦
相关分类