For Workes & Pages, what is the name of the domain?
Not relevant
What is the issue or error you’re encountering
I am trying to transform an image from an external URL (some public image) from within a Cloudflare Worker, and then upload the transformed image into R2. However, the transformation step simply doesn’t happen - it doesn’t throw any errors, it just doesn’t transform the image. I want to know if I can do what I am trying to do - and how.
What steps have you taken to resolve the issue?
const fit: 'cover' | 'scale-down' | 'contain' | 'crop' | 'pad' = 'cover';
const options = { cf: { image: { fit, height: 100, width: 100 } } };
// Run the request
const transformedImageResponse = await fetch(imageRequest, options);
// Check if the transformation was successful
if (!transformedImageResponse.ok) {
throw new Error(`Failed to transform image: ${transformedImageResponse.status}`);
}
// Upload transformed image to R2
let key = `internal/${uuid()}`;
const imageData = await transformedImageResponse.arrayBuffer();
const upload = await uploadTransformedImage(env, key, imageData);
Important observations:
(1) I am transforming EXTERNAL images (they are NOT stored on Cloudflare Images).
(2) I don’t want to return fetch
, because I don’t want to serve the transformed image right away. I want to upload the it to R2, and therefore I need the transformed image data.
How do I make this work?