gpt4 book ai didi

c++ - 使用 AWS C++ 接口(interface)将文件上传到 s3 时内容类型标签不正确

转载 作者:行者123 更新时间:2023-11-30 03:29:43 26 4
gpt4 key购买 nike

我正在尝试使用 AWS C++ SDK 将文件上传到 S3。文件传输正常,但内容类型是“二进制/八位字节流”而不是“文本/html”。当我在 S3 控制台中查看文件时。有一个类型为“text/html”的“x-amz-meta-content-type”元数据记录。如何设置我要上传的文件的实际内容类型?

int main (int, char**)
{
Aws::SDKOptions options;
Aws::InitAPI (options);
client = new Aws::S3::S3Client;

Aws::S3::Model::PutObjectRequest request;
request.SetBucket ("mywebsite.notreal.net");
request.SetKey ("index.html");
request.SetACL (Aws::S3::Model::ObjectCannedACL::public_read);
request.SetContentEncoding ("UTF-8");
request.AddMetadata ("Content-Type", "text/html");

auto inputData = Aws::MakeShared<Aws::FStream> ("PutObjectInputStream", "index.html", std::ios_base::in | std::ios_base::ate);
request.SetContentLength (inputData-> tellg ());
request.SetBody (inputData);

auto result = client-> PutObject (request);
return result.IsSuccess () ? 0 : 1;
}

v

最佳答案

Content-Type需要在实际的PUT请求中设置为HTTP头。

查看 documentation ,您可以使用 SetContentType 方法。

关于c++ - 使用 AWS C++ 接口(interface)将文件上传到 s3 时内容类型标签不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45489664/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com