【发布时间】:2016-09-02 06:30:35
【问题描述】:
我有一个 C++ 文件,用于将 avi 文件上传到 AWS S3 存储。 程序如下。
#include <aws/core/Aws.h>
#include <aws/s3/S3Client.h>
#include <aws/core/utils/HashingUtils.h>
#include <aws/s3/model/PutObjectRequest.h>
#include <iostream>
#include <fstream>
using namespace Aws::S3::Model;
using namespace std;
using namespace Aws::Utils;
static const char* KEY = "test.avi";
static const char* BUCKET = "testnmn";
int main()
{
Aws::SDKOptions options;
Aws::InitAPI(options);
const Aws::String bucket_name = BUCKET;
const Aws::String key_name = KEY;
const Aws::String dir_name = "/home/Softwares/Projects/S3upload/build";
std::cout << "Uploading " << key_name << " to S3 bucket: " <<
bucket_name << std::endl;
Aws::S3::S3Client s3_client;
Aws::S3::Model::PutObjectRequest object_request;
object_request.WithBucket(bucket_name).WithKey(key_name);
auto input_data = Aws::MakeShared<Aws::FStream>(key_name.c_str(), dir_name.c_str(), std::ios_base::in);
object_request.SetBody(input_data);
auto put_object_outcome = s3_client.PutObject(object_request);
if(put_object_outcome.IsSuccess()) {
std::cout << "Done!" << std::endl;
}
else {
std::cout << "PutObject error: " <<
put_object_outcome.GetError().GetExceptionName() << " " <<
put_object_outcome.GetError().GetMessage() << std::endl;
}
Aws::ShutdownAPI(options);
return 0;
}
运行exe文件时出现错误
Uploading test.avi to S3 bucket: testnmn
PutObject error: PermanentRedirect Unable to parse ExceptionName: PermanentRedirect Message: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
这个错误可能有什么问题?
谢谢
【问题讨论】:
-
这个问题你解决了吗?如果你已经完成了,你能分享一下如何解决吗?
标签: c++ amazon-web-services amazon-s3 aws-sdk