Do I have to enable CORS to use Supabase Storage with S3? #23198
Unanswered
ColeBlender
asked this question in
Questions
Replies: 3 comments
-
I am also interested in this. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Any update on this issue? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Same issue, apart from that I'm using Rails with ActionText that generates those signed URLs from the server. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have been using AWS S3 and want to switch to Supabase Storage. I already have all of my code written using the S3 SDK so I want to keep using that. I've followed the guide here https://supabase.com/docs/guides/storage/s3/authentication but it's still not working. Here is my code:
This is my route handler to generate a signed url
`
import { protect } from "@/lib/auth";
import { toS3SafeFormat } from "@/lib/utils";
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
import { NextRequest, NextResponse } from "next/server";
// upload-image
export async function POST(req: NextRequest) {
try {
await protect();
} catch (error) {
return NextResponse.json(
{ errorMessage: "Failed to generate upload url" },
{ status: 500 },
);
}
}
`
This is my code to upload it which takes place on the client
`
import { getErrorMessage } from "./utils";
import imageCompression from "browser-image-compression";
export async function uploadToS3(imageFile: File, folder: string) {
try {
const { url, fileKey, errorMessage } = await fetch(
"/api/s3/get-upload-url",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
fileName: imageFile.name,
folder,
}),
},
).then((res) => res.json());
} catch (error) {
return { errorMessage: getErrorMessage(error) };
}
}
`
Beta Was this translation helpful? Give feedback.
All reactions