Back

Error uploading PDF: [AppwriteException: Network request failed]

  • 0
  • Android
  • React Native
  • Web
De Pro
31 Mar, 2025, 01:22

here is the my code export const uploadPDF = async (pdf) => { try { console.log("Uploading file:", pdf);

TypeScript
const file = pdf.assets[0];
console.log("Uploading file:", file);

const result = await storage.createFile(
  process.env.EXPO_PUBLIC_APPWRITE_BOOKSHOP_BUCKET_ID,
  ID.unique(),
  file
);

if (!result || !result.$id) {
  throw new Error("Failed to upload PDF");
}

const pdfUri = `${process.env.EXPO_PUBLIC_APPWRITE_ENDPOINT}/storage/buckets/${process.env.EXPO_PUBLIC_APPWRITE_BOOKSHOP_BUCKET_ID}/files/${result.$id}/view?project=${process.env.EXPO_PUBLIC_APPWRITE_PROJECT_ID}`;
console.log("✅ PDF uploaded successfully:", pdfUri);

return pdfUri;

} catch (error) { console.error("❌ Error uploading PDF:", error); if (error.response) { console.error("Response:", error.response); } throw error; } };

and here are the logs

(NOBRIDGE) LOG Uploading file: {"assets": [{"mimeType": "application/pdf", "name": "Basic Real Analysis_ Along with a companion volume Advanced Real Analysis ( PDFDrive ).pdf", "size": 5292034, "uri": "file:///data/user/0/host.exp.exponent/cache/DocumentPicker/6081f92f-334d-413f-900e-17f166e15a23.pdf"}], "canceled": false} (NOBRIDGE) LOG Uploading file: {"mimeType": "application/pdf", "name": "Basic Real Analysis_ Along with a companion volume Advanced Real Analysis ( PDFDrive ).pdf", "size": 5292034, "uri": "file:///data/user/0/host.exp.exponent/cache/DocumentPicker/6081f92f-334d-413f-900e-17f166e15a23.pdf"} (NOBRIDGE) ERROR ❌ Error uploading PDF: [AppwriteException: Network request failed]

TL;DR
Error occurs when trying to upload a PDF file due to a network request failure. Check the code to ensure the correct bucket ID and project ID are being used. Also, verify connectivity and permissions.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more