slymnoyann/hey-1 · error · Error

Failed to upload file

Error message

Failed to upload file

What it means

Thrown by uploadFileToIPFS when the multi-file uploadToIPFS call resolves but the first response entry has no uri. It guards the contract that every successful upload yields a content URI, and it is the underlying failure surfaced by uploadCroppedImage's 'uploadFileToIPFS failed' error when uri is missing.

Source

Thrown at src/helpers/uploadToIPFS.ts:38

        acl: immutable(CHAIN.id)
      });

      return {
        mimeType: file.type || FALLBACK_TYPE,
        uri: storageNodeResponse.uri
      };
    })
  );

  return attachments;
};

export const uploadFileToIPFS = async (file: File): Promise<UploadResult> => {
  const ipfsResponse = await uploadToIPFS([file]);
  const metadata = ipfsResponse[0];

  if (!metadata?.uri) {
    throw new Error("Failed to upload file");
  }

  return { mimeType: file.type || FALLBACK_TYPE, uri: metadata.uri };
};

export default uploadToIPFS;

View on GitHub (pinned to 88c8f9d553)

Solutions

  1. Confirm the IPFS upload service is up and credentials/env vars are set in apps/web/.env
  2. Log the full ipfsResponse array to see the actual shape returned
  3. Check for storage quota or file-type restrictions on the upload endpoint
  4. Add retry and a user-facing failure message at the call site so users can retry the upload

Example fix

// before
const metadata = ipfsResponse[0];
if (!metadata?.uri) {
  throw new Error("Failed to upload file");
}

// after
const metadata = ipfsResponse?.[0];
if (!metadata?.uri) {
  console.error("IPFS upload returned no metadata", ipfsResponse);
  throw new Error("Failed to upload file");
}
Defensive patterns

Strategy: validation

Validate before calling

if (!(file instanceof File) || file.size === 0) {
  throw new Error("Cannot upload an empty file");
}
if (typeof navigator !== "undefined" && !navigator.onLine) {
  throw new Error("Cannot upload while offline");
}

Type guard

const hasUploadUri = (m: unknown): m is { uri: string } =>
  typeof m === "object" && m !== null && typeof (m as { uri?: unknown }).uri === "string" && (m as { uri: string }).uri.length > 0;

Try / catch

try {
  const result = await uploadFileToIPFS(file);
} catch (e) {
  if (e instanceof Error && e.message === "Failed to upload file") {
    // offer retry; log ipfsResponse shape for debugging
  }
  throw e;
}

Prevention

When it happens

Trigger: Uploading a File via uploadFileToIPFS where the IPFS endpoint returns an empty array, an object without uri, or undefined for the first entry. Also hit when the server renames the response field or returns a non-2xx-shaped body that the client parses into nothing.

Common situations: IPFS pinning service outage, exceeded storage quota, unauthenticated requests to the upload API due to missing env vars, or response schema drift between web client and API versions.

Related errors


AI-assisted analysis of slymnoyann/hey-1@88c8f9d553 (2026-08-28). Data as JSON: /api/errors/0d3c3de7f95ecf61. Report an issue: GitHub.