Mario84
Mario84

Reputation: 63

ReactJS and SupaBase - unzip an uploaded file and store in DB

What would be the most efficient way to handle unzipping of a file and storing then uploading the unzipped file to Supabase? There is no server-side available for SupaBase, so should I host an API elswhere that takes care of the unzipping part and eventually uploads the extracted file to SupaBase?

Upvotes: 0

Views: 358

Answers (1)

Mansueli
Mansueli

Reputation: 7024

Small Files (Supabase Only Solution)

For small files, you can create an Edge Function that uses a decompression stream:

const src = await Deno.open("./testdata/singleFile.txt.gz");
const dest = await Deno.open("./testdata/singleFile.txt", {
  create: true,
  write: true,
});
src.readable
  .pipeThrough(new DecompressionStream("gzip"))
  .pipeTo(dest.writable);

Then you can use this stream to pass the object to Supabase by tweaking this upload to storage example to take this decompression stream.

Large Files:

For large files, then it would probably be a better idea to create a server to extract and then upload it to Supabase Storage after the extraction was completed.

Upvotes: 1

Related Questions