0

我有一个 remix 操作函数,它接受一个文件作为 formData 请求对象,然后将其上传到 supabase。之后,我获取上传图片的 URL 并返回。

我的功能:

 const fileExt = filename.split(".").pop();
  const fileName = `${Math.random().toFixed(10)}.${fileExt}`;
  const filePath = `${fileName}`;

  const { error: uploadError } = await supabaseClient.storage
      .from("public")
      .upload(`misc/${filePath}`, stream);

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

    const { publicURL, error } = await supabaseClient.storage
      .from("public")
      .getPublicUrl(`misc/${filePath}`);
    if (error) {
      console.error(error);
      throw new Error(error.message);
    }
    !publicURL && console.error(`No public URL for ${filePath}`);

    return publicURL;

因为 formData 是 a multipart/form-data,所以我需要通过将上面的代码扔到 uploadHandler 函数中来解析它,然后:

const formData = await parseMultipartFormData(
    request,
    uploadHandler
 );

该代码有效,在其他时候,它失败并出现错误:据ECONNRESET我了解,这可能与节点异步代码有关,但我无法解决它。我怎样才能避免ECONNRESETSupabase 不断给出的那些随机错误?

4

0 回答 0