Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: fetch failed - Nextjs 13 #178

Open
1 of 2 tasks
felri opened this issue Sep 4, 2023 · 4 comments
Open
1 of 2 tasks

TypeError: fetch failed - Nextjs 13 #178

felri opened this issue Sep 4, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@felri
Copy link

felri commented Sep 4, 2023

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

Sending large files (5-20mb) always returns me fetch failed using Nextjs 13

To Reproduce

const uploadResult = await storageClient
  .from(STORAGE_BUCKET)
  .upload(filePath, file, {
    contentType: `video/${fileExt}`,
    upsert: true
  });

give me:

TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11522:11) {
  cause: Error: write EPIPE
      at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:94:16)
      at WriteWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
    errno: -32,
    code: 'EPIPE',
    syscall: 'write'
  }
}

Additional context

It seems that nextjs 13 removed node-fetch in favor of undici and this is causing a lot of problems, any chance that this bug is related to mine?

vercel/next.js#54961

@felri felri added the bug Something isn't working label Sep 4, 2023
@felri felri changed the title TypeError: fetch failed TypeError: fetch failed - Nextjs 13 Sep 4, 2023
@WildEgo
Copy link

WildEgo commented Sep 7, 2023

I have the same issue while using node 20, without next just standard node

@VCasecnikovs
Copy link

Having the same

@VCasecnikovs
Copy link

I have solved this problem for myself:

The problem happens, when I send File to Supabase Storage.

To solve the problem, I send Array Buffer:

let array_buffer = await image.arrayBuffer();

@KevinHCH
Copy link

Yeah, I had the same issue uploading imgs or audio files to supabase storage, I could solve using this function, so now, you can send any file to supabase storage.
Don't to forget to set the proper contentType

export const parseToArrayBuffer = async (file: Blob) => {
  const buffer = await file.arrayBuffer()
  const array = new Uint8Array(buffer)
  return array
}

// route.ts
const img = formData.get("avatar")
const imgBuffer = await parseToArrayBuffer(img as Blob)
const { data, error } = await supabase.storage.from(bucketName).upload(name, imgBuffer, {
    cacheControl: '3600',
    upsert: true,
    contentType: contentType,
  })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants