[b]"How can I use Puppeteer to upload a PDF to Supabase?"[/b] or [b]"Best way to upload a PDF to Supabase using Pu

14 Replies, 1148 Views

"Trouble uploading a PDF to Supabase with Puppeteer—any solutions?"

Hey folks!

Been trying to figure out how to use puppeteer upload pdf to supabase, but hitting a wall.

I can generate the PDF just fine, but the upload part keeps failing. Tried using `page.uploadFile()`, but Supabase doesn’t seem to play nice with it.

Anyone got this working? Maybe a workaround or a better approach?

Or am I just missing something obvious? lol

Thanks in advance!

(Also, if you’ve done puppeteer upload pdf to supabase successfully, pls share your code snippet—would be a lifesaver!)
Hey! Had the same issue last week. Instead of using `page.uploadFile()`, I converted the PDF to a Blob and used Supabase's `storage.from('bucket').upload()` directly.

Here's a quick snippet:
```javascript
const pdfBuffer = await page.pdf();
const { data, error } = await supabase.storage.from('pdfs').upload('file.pdf', pdfBuffer);
```
Works like a charm! Also, check out Supabase's docs on file uploads—super helpful for puppeteer upload pdf to supabase workflows.
Yo! Supabase doesn’t handle Puppeteer’s file upload the same way as a browser form. Try this:

1. Save the PDF locally first.
2. Use `fs.readFileSync` to get the buffer.
3. Upload via Supabase JS client.

Bonus: If you’re dealing with large files, chunking might help. Let me know if you need the chunking code!
Struggled with puppeteer upload pdf to supabase too. Found that `page.uploadFile()` is flaky with Supabase’s API.

Workaround: Use `page.pdf()` to get the buffer, then POST it via fetch or the Supabase SDK.

Also, make sure your bucket permissions are set to public/private correctly. That tripped me up for hours lol.
If you’re generating the PDF with puppeteer, skip the file step entirely! Just grab the buffer from `page.pdf()` and push it straight to Supabase storage.

Code:
```javascript
const pdf = await page.pdf({ format: 'A4' });
await supabase.storage.from('bucket').upload('output.pdf', pdf);
```
No temp files, no fuss. Works every time for me.
Wow, thanks everyone! Didn’t realize I could skip the file step entirely and just use the buffer. Tried the `page.pdf()` + direct upload approach, and it worked!

One follow-up: What’s the best way to handle errors if the upload fails? Should I retry or just log it?

Also, big thanks for the RLS reminder—totally forgot to check that. You all saved me hours of headache!
Hey! Had this exact puppeteer upload pdf to supabase problem. Turns out, Supabase expects raw bytes, not a file path.

Try this:
- Generate PDF with `page.pdf()`.
- Convert to Blob or use the buffer directly.
- Upload with `supabase.storage.upload()`.

Also, double-check your RLS policies if it’s still failing.
Supabase + Puppeteer can be tricky for file uploads. Instead of `uploadFile()`, I used `page.pdf()` to get the buffer and then:

```javascript
const { error } = await supabase
.storage
.from('pdfs')
.upload('doc.pdf', await page.pdf());
```
If you’re still stuck, maybe try logging the error object? Might give you a clue.



Users browsing this thread: 1 Guest(s)