-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
guidanceQuestion that needs advice or information.Question that needs advice or information.
Description
I am trying to upload a .jpg to my bucket and get this error
PutObject error: Unable to connect to endpoint
My function looks like this to upload the image to S3
inline void
uploadToS3(Aws::String bucket_name, Aws::String key_name, Aws::String file_path)
{
Aws::SDKOptions options;
Aws::InitAPI(options);
Aws::Client::ClientConfiguration clientConfig;
clientConfig.scheme = Aws::Http::Scheme::HTTPS;
clientConfig.region = Aws::Region::US_WEST_1;
Aws::S3::S3Client s3_client(clientConfig);
clientConfig.connectTimeoutMs = 30000;
clientConfig.requestTimeoutMs = 600000;
Aws::S3::Model::PutObjectRequest object_request;
object_request.WithBucket(bucket_name).WithKey(key_name);
auto input_data = Aws::MakeShared<Aws::FStream>("PutObjectInputStream",
file_name.c_str(), std::ios_base::in | std::ios_base::binary | std::ios_base::trunc);
object_request.SetBody(input_data);
object_request.SetContentType("image/jpeg");
object_request.SetContentLength(static_cast<long>(51908));
auto put_object_outcome = s3_client.PutObject(object_request);
if (put_object_outcome.IsSuccess())
{
LOG_INFO("Uploaded to bucket");
}
else
{
std::cout << "PutObject error: " <<
put_object_outcome.GetError().GetExceptionName() << " " <<
put_object_outcome.GetError().GetMessage() << std::endl;
}
Aws::ShutdownAPI(options);
}
I have to do SetContentLength otherwise I get a
BadRequest Message: An error occurred when parsing the HTTP request.
error
I use this function like so:
Aws::String file_path = "testimage1.jpg";
Aws::String bucket_name = "dummy";
Aws::String key_name = "key"; //secret key
uploadToS3(bucket_name, key_name, file_path);
I attach the log where I get the error code 28 error. I'm not sure how to fix this error. thanks!
Metadata
Metadata
Assignees
Labels
guidanceQuestion that needs advice or information.Question that needs advice or information.