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년 전721회 조회
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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠