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
已提問 2 年前檢視次數 719 次
1 個回答
0
已接受的答案

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

LorenDB
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南