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
- Appwrite-injected variables are not avai...
I am using rust-1.83 as a runtime and try to access APPWRITE_FUNCTION_API_ENDPOINT or APPWRITE_FUNCTION_API_KEY during runtime. Both are not set during my execu...
- Functions in cloud console not works
please advise as all of my runing functions on Appwrite console was working before , but now it give this error [Invalid `headers` param: Value must be a valid...
- [SOLVED] Production down - createExecuti...
Hey, Since 1.9.6 rollout in fra (~17:00 UTC, 14 Aug), POST /v1/functions/{functionId}/executions returns a 400 whenever the body includes an empty headers ob...