Hi everyone,
Your help would be greatly appreciated! This is probably a very easy one for someone in the know.
When I’m uploading to my R2 bucket, my upload works and is successful; although I can’t work out how to get the object ID of the content I just uploaded.
Am I supposed to get the object ID from the pre-signing process? Or from the actual PUT?
The response from the PUT request is empty, nothing in the body at all… their is an Etag in the header but that’s all.
When I use a pre-signed URL to put the image in a <img src=“” the image works correctly, everything is fine… so it’s like the upload has worked, just no object ID provided.
I just can’t work out how to get the Object ID of the image?
I need this in order to use the image in Cloudflare Image transformations.
Thank you so much for your time!
Anthony
Here is my PHP pre-signing code
$bucket_name = x;
$account_id = x;
$access_key_id = x;
$access_key_secret = x;
$credentials = new Aws\Credentials\Credentials ($access_key_id, $access_key_secret);
$options = [
‘region’ => ‘auto’,
‘endpoint’ => x,
‘version’ => ‘latest’,
‘credentials’ => $credentials
];
$r2_client = new Aws\S3\S3Client ($options);
$cmd = $r2_client->getCommand (‘GetObject’, [
‘Bucket’ => $bucket_name,
‘Key’ => $file_name
]);
$request = $r2_client->createPresignedRequest ($cmd, ‘+5 minute’);
$url = ((string) $request->getUri ());
return $url;
Here is the jQuery code that does the actual PUT:
$.ajax ({
cache: false,
contentType: false,
data: file,
enctype: false,
processData: false,
type: ‘PUT’,
url: response.url,
success: function (d) {
console.log (d); // This response is empty