Sign UploadPartRequest for MultipartUpload with ChecksumAlgorithm #2443
-
Hello all, I am trying to generate a Presigned URL for an UploadPartRequest of a MultipartUpload.
then this way I can create the given URL to the part with the part number :
But If I set the ChecksumAlgorithm when starting the MultipartUpload I get trouble: If I generate the presigned the same way I created it before and try to make a PUT to the generated signed URL I get Adding the Header
But using this presiged url produces another error:
In the request headers a set the I use the aws-sdk-cpp/1.11.51 to start the multipart upload and generate the predefined URL, and Insomnia to send the PUT request. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Check out our tests to see how this can be used. I think this test is similar to what you are trying: static void DoPresignedUrlTest(const Aws::String& bucketName, std::shared_ptr<HttpRequest>& putRequest)
{
std::shared_ptr<Aws::IOStream> objectStream = Aws::MakeShared<Aws::StringStream>("BucketAndObjectOperationTest");
*objectStream << "Test Object";
objectStream->flush();
putRequest->AddContentBody(objectStream);
Aws::StringStream intConverter;
intConverter << objectStream->tellp();
putRequest->SetContentLength(intConverter.str());
putRequest->SetContentType("text/plain");
std::shared_ptr<HttpResponse> putResponse = m_HttpClient->MakeRequest(putRequest);
ASSERT_EQ(HttpResponseCode::OK, putResponse->GetResponseCode());
ASSERT_TRUE(WaitForObjectToPropagate(bucketName, TEST_OBJ_KEY));
// GetObject with presigned url
Aws::String presignedUrlGet = Client->GeneratePresignedUrl(bucketName, TEST_OBJ_KEY, HttpMethod::HTTP_GET);
std::shared_ptr<HttpRequest> getRequest = CreateHttpRequest(presignedUrlGet, HttpMethod::HTTP_GET, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod);
std::shared_ptr<HttpResponse> getResponse = m_HttpClient->MakeRequest(getRequest);
ASSERT_EQ(HttpResponseCode::OK, getResponse->GetResponseCode());
Aws::StringStream ss;
ss << getResponse->GetResponseBody().rdbuf();
ASSERT_STREQ("Test Object", ss.str().c_str());
Aws::S3::Model::GetObjectRequest getObjectRequest;
getObjectRequest.WithBucket(bucketName).WithKey(TEST_OBJ_KEY);
auto outcome = Client->GetObject(getObjectRequest);
AWS_ASSERT_SUCCESS(outcome);
if (putRequest->HasHeader(Aws::S3::SSEHeaders::SERVER_SIDE_ENCRYPTION))
{
ASSERT_STREQ(Aws::S3::Model::ServerSideEncryptionMapper::GetNameForServerSideEncryption(outcome.GetResult().GetServerSideEncryption()).c_str(), putRequest->GetHeaderValue(Aws::S3::SSEHeaders::SERVER_SIDE_ENCRYPTION).c_str());
}
} |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
Check out our tests to see how this can be used. I think this test is similar to what you are trying: