Hi !
Calling getFlieView form the node sdk give a buffer containing the full text of the file instead of URL.href ?
const csvFile = await sdk.InputFile.fromPlainText(csvString, `batch_${batchId}.csv`);
const storageReponse = await storage.createFile("batch_cards_csv", batchId, csvFile);
const fileView = await storage.getFileView("batch_cards_csv", storageReponse.$id);
// Debugging
console.log("type", typeof fileView);
console.log("fileview Object", fileView);
console.log("fileview", fileView.toString());
console.log("href", fileView.href);
log output:
type object
fileview Object {"type":"Buffer","data":[49,44,104,116,116,112,115,58,47,47,108,11 ...
fileview 1,https://localhost:5173/card/nwbEC
2,https://localhost:5173/card/RSugw
3,https://localhost:5173/card/60Sm8
4,https://localhost:5173/card/vPf73...
Is there another way to get the href or i am missing something ?
PS: The file is correctly created and i can get the url in the appwrite UI. But not in the sdk.
Yes, this is expected. The url to the file is the path in the docs: https://appwrite.io/docs/server/storage?sdk=nodejs-default#storageGetFileView
Why do you need the url?
Yeah this work too. I need the url to make the client download the file automatically. If there is another way than using an hidden link and click() it would be better than this solution. I got it working by getting the link using the web-sdk :
const storageResponse = await storage.getFileDownload("batch_cards_csv", batchId);
const link = await createClientLink(storageResponse.href);
I download the file via xhr and then use
const link = (window.URL ? window.URL : window.webkitURL).createObjectURL(blob);
setDownloadLink(link);
set the link to an hidden link
<a ref={downloadLinkRef} href={downloadLink} download={`batch.csv`} style={{ display: "none" }}></a>
then click on it
downloadLinkRef.current.click();
So the user doesn't leave the current page.
Yes, this is the correct way to do it client side
Ok thanks for your reactivity !
Recommended threads
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...
- Project in AppWrite Cloud doesn't allow ...
I have a collection where the data can't be opened. When I check the functions, there are three instances of a function still running that can't be deleted. The...
- Get team fail in appwrite function
I try to get team of a user inside appwrite function, but i get this error: `AppwriteException: User (role: guests) missing scope (teams.read)` If i try on cl...