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

StorageUnknownError: fetch failed | NestJS #161

Open
karrtopelka opened this issue Apr 14, 2023 · 2 comments
Open

StorageUnknownError: fetch failed | NestJS #161

karrtopelka opened this issue Apr 14, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@karrtopelka
Copy link

Hello, I am trying to upload an image to existing public bucket

async updateAvatar(file: Express.Multer.File) {
    const { originalname, mimetype, buffer } = file;

    const { data, error } = await this.storage
      .from('avatars')
      .upload(`public/${originalname}`, buffer, {
        contentType: mimetype,
        upsert: false,
      });

    if (error) {
      throw new Error(error.message);
    }

    return data;
  }

But getting error:

{
  data: null,
  error: StorageUnknownError: fetch failed
      at /Users/karrtopelka/Documents/business_idea/proposal/server/node_modules/@supabase/storage-js/src/lib/fetch.ts:32:12
      at Generator.next (<anonymous>)
      at fulfilled (/Users/karrtopelka/Documents/business_idea/proposal/server/node_modules/@supabase/storage-js/dist/main/lib/fetch.js:5:58)
      at processTicksAndRejections (node:internal/process/task_queues:95:5) {
    __isStorageError: true,
    originalError: TypeError: fetch failed
        at Object.fetch (node:internal/deps/undici/undici:14294:11)
        at processTicksAndRejections (node:internal/process/task_queues:95:5) {
      cause: [Error]
    }
  }
}

Here is my service:

import { Injectable } from '@nestjs/common';
import { StorageClient } from '@supabase/storage-js';

@Injectable()
export class SupabaseService extends StorageClient {
  constructor() {
    super(process.env.STORAGE_URL, {
      apikey: process.env.API_SECRET,
      Authorization: `Bearer ${process.env.API_SECRET}`,
    });
  }
}

What can be the issue?
Found unanswered question but with svelte: https://github.com/supabase/supabase/discussions/12389_

@karrtopelka karrtopelka added the bug Something isn't working label Apr 14, 2023
@FinesseLineUp
Copy link

FinesseLineUp commented Apr 27, 2023

receive the same error for all supabase.storage requests in Expo app: stack: "StorageUnknownError: Network request failed\n at construct (native)\n at apply (native)\n at _construct (http://192.168.0.103:19000/node_modules/expo/
__isStorageError: true

@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();

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

3 participants