简体   繁体   English

使用AWS c ++界面将文件上传到s3时Content-Type标记不正确

[英]Content-Type tag incorrect when uploading file to s3 using the AWS c++ interface

I'm trying to upload a file to S3 using the AWS C++ SDK. 我正在尝试使用AWS C ++ SDK将文件上传到S3。 The file transfers just fine but the content type is "binary/octet-stream" instead of "text/html". 文件传输很好,但是内容类型是“ binary / octet-stream”而不是“ text / html”。 When I look at the file in the S3 console. 当我在S3控制台中查看文件时。 There is a "x-amz-meta-content-type" metadata record of type "text/html". 存在类型为“ text / html”的“ x-amz-meta-content-type”元数据记录。 How can I set the actual content type of the file I want to upload? 如何设置要上传的文件的实际内容类型?

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 v

The Content-Type needs to be set as an HTTP header in the actual PUT request. 在实际的PUT请求中,需要将Content-Type设置为HTTP标头。

Looking at the documentation , there's a SetContentType method you can use. 查看文档 ,可以使用SetContentType方法。

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

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