Any idea how to debug / solve 401 unauthorized errors when using pre signed urls? My r2 bucket cors

Any idea how to debug / solve 401 unauthorized errors when using pre signed urls?

My r2 bucket cors policy is
[
  {
    "AllowedOrigins": [
      "*"
    ],
    "AllowedMethods": [
      "GET",
      "PUT",
      "POST",
      "HEAD",
      "DELETE"
    ],
    "AllowedHeaders": [
      "*"
    ],
    "ExposeHeaders": [],
    "MaxAgeSeconds": 3000
  }
]


I've tried many different combinations, the code that generates the pre signed url

    const signedUrl = await getSignedUrl(
            r2,
    new PutObjectCommand({
        Bucket: process.env.R2_BUCKET_NAME,
        Key: filename,
        }),
    { expiresIn: 3600 },
    );
Screenshot_2024-03-25_at_11.06.46_AM.png
Was this page helpful?