Rank 3: Container
how can i achive uploading a file to storage, using a url?
i attach a photo of an example i want to do, is that possible and any hints on how to do it?
Votes
0
Replies
12
Participants
Unknown
Messages
13
Rank 3: Container
how can i achive uploading a file to storage, using a url?
i attach a photo of an example i want to do, is that possible and any hints on how to do it?
You cant
Rank 3: Container
There is no possible way??? Tried to fetch it and parse the buffer to it but did not work sadly
Admin
You should be able to upload via a buffer
Rank 3: Container
async function uploadImage( imageUrl, imageName, bucketId = process.env.IMAGES_BUCKET_ID) { try { const imageResponse = await fetch(imageUrl); if (!imageResponse.ok) { throw new Error("Failed to fetch image from URL"); }
const arrayBuffer = await imageResponse.arrayBuffer(); const buffer = Buffer.from(arrayBuffer);
const inputFile = sdk.InputFile.fromBuffer(buffer, imageName);
const result = await storage.createFile(bucketId, ID.unique(), inputFile); return result; } catch (error) { console.error("Error uploading image:", error); throw error; }}Rank 3: Container
Seems correct to me
Rank 3: Container
Error uploading image: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type number (3798243238)
Rank 3: Container
Ah nvm see the error imageName should be an string
Admin
What sdk are you using?
Rank 3: Container
Appwrite
Rank 3: Container
const sdk = require("node-appwrite");
Admin
Maybe you can use InputFile.fromBlob(await imageResponse.blob())
Btw there's a new version of the node sdk
Rank 3: Container
I tried updating lately and had loads of errors... So I just went back to the old one