Ok, I’ve spent a little bit of time looking at this, and while I don’t have a satisfactory solution at the moment, I have some observations to share that may help us in debugging the issue going forward.
Firstly - and I am going to assume that this is not the problem you are dealing with - I needed to make sure to remove the lines in HelloStorj.js
related to deleting the bucket and file at the end. This way I can debug more easily:
Secondly, I made sure the encryption passphrase, api key, and satellite URL are exactly the same as the ones I used in my access for the uplink
cli tool (recent binary downloads for the cli tool, some documentation for the cli tool). That way, when I upload a file with HelloStorj.js
, I can download it with uplink
to determine whether the upload succeeded. I am happy to provide more information about using the uplink cli if needed.
Anyway, once I did the steps above, I ran the script with a variety of files (against us1.storj.io, if that matters). First, I tried a 158 MB mp4. The js script created the bucket successfully, successfully uploaded the file, and “successfully” downloaded the file. The downloaded file was the correct size, but it did not match the file I uploaded (and could not be opened with a video player).
Interestingly, when I downloaded the file with the uplink cli, it matched the original and played correctly. So for me, the upload phase of HelloStorj.js
worked perfectly - it was the download that messed up.
I experimented with some more files of different sizes. Most relevant were:
- a 3 kB text file -
HelloStorj.js
managed to successfully upload and download this file, and the original matched the downloaded file. Success! But this is a tiny file, and is in fact stored inline rather than split up and stored across storagenodes. So not very impressive.
- a 28 MB text file - this had the same issue as the mp4 I tried uploading earlier (download didn’t match original). The difference is that because it was a text file, I had an easier time determining the issue.
Check this out:
cmp downloaded.txt ~/original.txt
downloaded.txt /home/moby/original.txt differ: byte 7409, line 110
The file actually matches all the way until the 110th line. In fact, the vast majority of the first 30k lines are identical between the two files (the original file is more like 300k lines). Anywhosies, this means that the issue isn’t some decryption issue. When I opened both files in a text editor, I noticed a lot of ^@
characters (null characters) in the bad downloaded file. In fact, when I did a find/replace on the null characters to remove them, the file went from 28 MB to 2.7 MB - meaning 90% of the file downloaded was null characters!
So tldr, it looks like (for me), the JS implementation works reliably for uploads of a variety of sizes (haven’t tested anything super huge, but at least up to around 150 MB). But for downloads of files larger than a few kB, it does not succeed reliably. I am not sure the exact reason, but it appears that we are writing lots of null bytes to the file during the download. But I can download those files just fine with the uplink CLI, so it is definitely an issue specific to the Nodejs implementation of download.
I am sorry I wasn’t able to help more, and I’m not even sure if the issue I am experiencing is the same as yours. Hopefully someone else can follow similar steps as me and see if they observe the same problem - then perhaps we will be a little closer to finding the root of this bug.