Images uploaded to R2 are broken

Hi there!

I’m trying to upload images to my R2 bucket at my node application using aws-sdk like I used to do at S3.

My frontend requests a presigned URL for PutObjectCommand, the backend returns it and then I upload the image with fetch api and form data containing the file.

I can see the uploaded file at my bucket with correct path and type, but when I download it the image is broken and not openable.

I also tried uploading the image with Curl to follow the documentation example. The result is the same, so I think it’s not a problem at the client request, seems to be related to the PutObjectCommand presigned URL.

Can someone please help me understand what I’m doing wrong? Thanks!

I found the problem.

Before moving to Cloudflare R2 I was using an older version of aws-sdk that used to work when sending a FormData.

I updated the packages at the same time that I moved to R2 and now I shouldn’t be sending FormData anymore. Using Readable Stream or passing the Blob directly at the body instead like at this [docs]( worked