sdk-for-node icon indicating copy to clipboard operation
sdk-for-node copied to clipboard

📚 Documentation: storageCreateFile / server / node

Open Amerlander opened this issue 3 years ago • 4 comments

💭 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 image

image

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?

Amerlander avatar Apr 16 '22 14:04 Amerlander

@Amerlander thank you for pointing this out.

lohanidamodar avatar Apr 20 '22 07:04 lohanidamodar

Please assign this to me, I'll take a look today :)

gewenyu99 avatar Apr 20 '22 14:04 gewenyu99

Any news on this? I'm having the same problem

gepd avatar May 01 '22 06:05 gepd

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.

gewenyu99 avatar May 09 '22 20:05 gewenyu99

Oops, this is old :)

It's been merged!

gewenyu99 avatar Sep 16 '22 19:09 gewenyu99