Austin
Austin

Reputation: 335

Supabase storage - Error Failed to load PDF document

I have a PDF which has been uploaded to Supabase storage. I can click download via the dashboard and can view my downloaded PDF locally or in chrome.

When I click Get Url or programmatically get the public URL, opening that in Chrome leads to an error with Error Failed to load PDF document. I'd like to be able to serve this PDF to my users in my Next.js app.

I have enabled an RLS policy on the bucket which allows everything for public, and the bucket itself is public.

Upvotes: 2

Views: 873

Answers (1)

Austin
Austin

Reputation: 335

I ended up having to use contentType: "application/pdf" in the FileOptions when uploading. Not sure why it can infer the MIME type on console upload, but not programmatically.

const { data, error } = await supabase.storage.from('bucket').upload(uploadPath, pdfBytes, {upsert: true, contentType: "application/pdf"});

Upvotes: 0

Related Questions