Web Developer
here is the my code
export const uploadPDF = async (pdf) => {
try {
console.log("Uploading file:", pdf);
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]