New object store file upload example
jmordica opened this issue · comments
When using NodeJS to upload a file via like:
await os.put({name: 'filename.gz'}, this.readableStreamFrom(fs.readFileSync(./filename.gz)))
readableStreamFrom(data: Uint8Array): ReadableStream<Uint8Array> {
return new ReadableStream<Uint8Array>({
pull(controller) {
controller.enqueue(data);
controller.close();
}
})
}
The file uploads properly but when downloading the file (using nats cli) it is corrupt and wont extract. It shouldn't matter but the example uses a gzipped file.
Any pointers for how the file should be passed in? The example is just encoding/decoding a string but I believe files are read in as a buffer type.
Thanks.
My guess is that because it is a Buffer, there may be some unexpected data in there...
Perhaps try obtaining the ArrayBuffer from Node's Buffer, and then creating an Uint8Array from it.
I went to look at the implementation, and it is possible for an entry to not have a hash, which would trigger it as being corrupt. Posting a fix right now.
This may not be your issue exactly, but could be, I will release @next versions of nats.ws so you can test.
@jmordica npm install nats.ws@next
to get 1.10.0-1
Sweet! Installing the new version worked! For anyone else dealing with this here's how I am now successfully uploading a file to object store:
await os.put({name: 'someFile.gz'}, this.readableStreamFrom(fs.readFileSync('path/to/someFile.gz')));