I had uploaded a .txt file to AWS S3 bucket. on opening file, it showed data like
aHR0cHM6Ly90ZXN0LnNhbGVzZm9yY2UuY29tLw==
If we pass this string data aHR0cHM6Ly90ZXN0LnNhbGVzZm9yY2UuY29tLw==
based on the util provided by
https://gist.github.com/nxtr/bca4984cd3753261995c421711729629
displayed actual correct data present in the txt file as "https://test.salesforce.com/".
So how can we upload file .txt into AWS S3 bucket, that actually displays correct data "https://test.salesforce.com/" instead of aHR0cHM6Ly90ZXN0LnNhbGVzZm9yY2UuY29tLw==
Can anyone please help. thanks,
Thanks for reply @sfdcfox these are my observations 1) file uploaded successfully, but with above issues, this is the request
String url = 'https://' + this.bucketName + '.s3.amazonaws.com/' + this.folderName + '/' + this.fileName;
HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('PUT');
req.setHeader('X-Amz-Content-SHA256', this.getXAmzContent());
req.setHeader('X-Amz-Date', this.timestamp);
req.setHeader('Authorization', this.getPutAuthHeader());
req.setBody(body);
2) Then tried your code,
String url = 'https://' + this.bucketName + '.s3.amazonaws.com/' + this.folderName + '/' + this.fileName;
HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('PUT');
req.setHeader('X-Amz-Content-SHA256', this.getXAmzContent());
req.setHeader('X-Amz-Date', this.timestamp);
req.setHeader('Authorization', this.getPutAuthHeader());
Blob testBlob = EncodingUtil.base64Decode(body);
if(testBlob.size() > 0) {
req.setHeader('Content-Length', String.valueOf(testBlob.size()));
req.setBodyAsBlob(testBlob);
}
getting this error
<Code>XAmzContentSHA256Mismatch</Code><Message>The provided 'x-amz-content-sha256' header does not match what was computed.</Message><ClientComputedContentSHA256>
What mistake I making ?