sdk-for-node
sdk-for-node copied to clipboard
📚 Documentation: storageCreateFile / server / node
💭 Description
The documentation for storageCreateFile seems wrong: https://appwrite.io/docs/server/storage?sdk=nodejs-default#storageCreateFile
For the file parameter, there is only a string allowed:
https://github.com/appwrite/sdk-for-node/blob/4f021b92b6ddf5598d5d8c66c410b8056788d16c/lib/services/storage.js#L334
https://github.com/appwrite/sdk-for-node/blob/4f021b92b6ddf5598d5d8c66c410b8056788d16c/lib/services/storage.js#L340
The code Example and the description are claiming, that I can provide a binary file:
https://appwrite.io/docs/server/storage?sdk=nodejs-default#storageCreateFile


This works but is different from what is in the documentation):
const filename = './tmp/1.jpg';
let promise = storage.createFile(BUCKET_ID, id, filename);
Following the documenttation, this should, but does not work (also is not giving any error, or I might have overseen them):
const file = new File([uin8array], '1.jpg', {type: 'image/jpeg'})
let promise = storage.createFile(BUCKET_ID, id, file);
If I provide different things as file I get Type Errors, which are telling, that it would work to provide either a String or a Uint8Array. Both does not work:
const url = 'https://sample.com/1.jpg'
const response = await fetch(url)
const image = await response.arrayBuffer();
const uin8array = new Uint8Array(image);
let promise = storage.createFile(BUCKET_ID, id, uin8array);
-> TypeError [ERR_INVALID_ARG_VALUE]: The argument 'path' must be a string or Uint8Array without null bytes. Received Uint8Array(178056)
const url = 'https://sample.com/1.jpg'
const response = await fetch(url)
const image = await response.arrayBuffer();
const uin8array = new Uint8Array(image);
const imageString = new TextDecoder().decode(uin8array);
let promise = storage.createFile(BUCKET_ID, id, imageString);
->TypeError [ERR_INVALID_ARG_VALUE]: The argument 'path' must be a string or Uint8Array without null bytes. Received '����\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00...'
👀 Have you spent some time to check if this issue has been raised before?
- [X] I checked and didn't find similar issue
🏢 Have you read the Code of Conduct?
- [X] I have read the Code of Conduct
@Amerlander thank you for pointing this out.
Please assign this to me, I'll take a look today :)
Any news on this? I'm having the same problem
Any news on this? I'm having the same problem
The PR was merged :) The examples will be updated.
Thank you guys for pointing this out, and thank you for your pateince.
Oops, this is old :)
It's been merged!