Attempting to programmatically replace file results in "No response body" (C++)

0

In my C++ project using the S3 API, I have a function that boils down to something like this:

void replaceFile(const std::string &key, const std::string &filePathToUpload, std::function<void (const Aws::S3::Model::PutObjectOutcome &)> successCallback, std::function<void (const Aws::S3::Model::PutObjectOutcome &)> failureCallback)
{
	Aws::S3::S3Client client;
	Aws::S3::Model::PutObjectRequest req;
	req.SetBucket("name of my bucket");
	req.SetBody(std::make_shared<std::fstream>(filePathToUpload));
	req.SetACL(Aws::S3::Model::ObjectCannedACL::public_read);
	req.SetKey(key);
	if (auto outcome = client.PutObject(req); outcome.IsSuccess())
		successCallback(outcome);
	else
		failureCallback(outcome);
}

Basically, I want to replace files that I have already uploaded. (I suppose I could really just re-upload the file; I hadn't thought about that till now. However, the upload function has the same problem.) Unfortunately, this function won't work. It sends data to AWS but ends up with an error "No response body." This error is HTTP 400 and has the internal error code 100 for Aws::S3::S3Errors::UNKNOWN. I checked the SDK issue list for issues involving this error message and found a few that looked similar, but they all involved HEAD, not PUT. Is the SDK doing a HEAD request behind my back? Am I missing something? What is wrong?

I'm running this on openSUSE Tumbleweed with SDK version 1.9.180 (OK, OK, I'm using master main, but that's the same thing).

Thanks in advance.

LorenDB
asked 2 years ago704 views
1 Answer
0
Accepted Answer

I solved my own problem: the file path I sent to std::fstream was null, so AWS wasn't receiving any data.

LorenDB
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions