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
- MongoDb Database Breaks integer[] & bigi...
I've got a table with the below column created. When I try to insert the value `[-3408048000]` into it, the dart sdk cloud function call is successful (no error...
- Appwrite Functions cold start
Hello. I'm seeing really long cold starts on Appwrite Cloud Functions and wanted to know if this is expected. My function just authenticates the user, fetches ...
- Error can not create `tablesdb` event wi...
When i'm trying to add an event with `tablesdb` i get an error message My event value: `tablesdb.mtg-decklist-dev.tables.queue_parsing.rows.*.create` Same err...