./zbox upload command is used to upload a file on dStorage. Parameters for uploading a file to dStorage can be viewed by using the ./zbox upload --help command.
Here are the Parameters :
Example :
Let's upload an info.txt file to allocation, the local path for the file is mapped to a local variable and the remote directory is mapped to a remote variable which is myfiles/info.txt.
Verify whether the uploaded file is available on dStorage using list command required parameters are allocation ID and remote path
./zbox list --remotepath $remote --allocation $ALLOC
Response:
TYPE | NAME | PATH | SIZE | NUM BLOCKS |LOOKUP HASH |
IS ENCRYPTED | DOWNLOADS PAYER
+------+----------+-------------------+------+------------+-----------------------------------------------
f | info.txt | /myfiles/info.txt | 24 | 4 | f15383a1130bd2fae1e52a7a15c4322
69eeb7def555f1f8b9b9a28bd9611362c | NO | owner
The response yields a lookuphash which works as a unique identifier for the uploaded file. Since you uploaded the file, the download payer section will show it as owner.
Copy and mark your lookup hash to a variable as it will be used for performing other file operations
export LOOKUPHASH=f15383a1130bd2fae1e52a7a15c432269eeb7def555f1f8b9b9a28bd9611362c
Uploading an Encrypted File to dStorage
Parameters for encrypting and uploading a file to dStorage are almost the same as uploading a file on dStorage and only requires an additional --encrypt flag with the command.
For instance if we want to encrypt and upload a sample info.txt file the command would be:
24 / 24 [================================================================] 100.00% 0s
Status completed callback. Type = application/octet-stream. Name = info.txt
To verify whether the file is encrypted and uploaded to dstorage use the list command :
./zbox list --allocation $ALLOC --remotepath $remote
Response:
TYPE | NAME | PATH | SIZE | NUM BLOCKS |LOOKUP HASH
| IS ENCRYPTED | DOWNLOADS PAYER
+------+----------+-------------------+------+------------+-----------------------------------------------
f | info.txt | /myfiles/info.txt | 24 | 4 | f15383a1130bd2fae1e52a7a15c432269
eeb7def555f1f8b9b9a28bd9611362c | YES | owner
Scroll right in the response and check the IS ENCRYPTED section, it will say YES if the file is encrypted.
Updating the contents of a file on dStorage
Use ./zbox update command to update the content of an existing file in the remote path. Like upload command. Only the owner of the allocation or a collaborator can update a file. To add collaborators to an allocation, check File Collaboration.
Parameters for updating the contents of the file on dStorage can be seen by typing ./zbox update --help
Note: To verify whether directory is created successfully run List all files command.
Sharing a File on dStorage
Zbox supports sharing of files using auth tokens. Sharing can be encrypted or not encrypted for this section we will describe the non-encrypted share functionality. For encrypted shared functionality have a look at Private Sharing .
./zbox share command is used to generate an authtoken that provides authorization to the holder to the specified file on the remotepath. Parameters for sharing the file can be viewed using the ./zbox share --help
If you are not able to download files and getting Error in file operation: File content didn't match with uploaded file response check Error 2 in Tips and Troubleshooting Section.
Download using Authticket
The necessary flags for downloading the file using the Authticket is auth ticket and local path. Get the AuthToken for the file on dstorage from another user and mark it to a variable. We will use auth token created and marked to AUTH variable for the file we shared in sharing a file on dStorage section .
28 / 28 [==========================================================] 100.00% 0s
Status completed callback. Type = application/octet-stream. Name = info.txt
As you can see Zbox has identified the file(info.txt) based on the auth token and didn't require any remote path and allocation id.
Deleting a File from dStorage
Deleting the file on dStorage can be done using the ./zbox delete command. Parameters for deleting the contents of the file on dStorage can be seen by typing ./zbox delete --help
Verify whether the updated txt file is available on dstorage using the list command
./zbox list --remotepath $remote --allocation $ALLOC
Response:
TYPE | NAME | PATH | SIZE | NUM BLOCKS | LOOKUP HASH | IS ENCRYPTED | DOWNLOADS PAYER
+------+------+------+------+------------+-------------+--------------+-----------------+
As you can see the file is not showing in remote directory which means the file has been successfully deleted.
Copy File to Another Existing Folder in dStorage
Use ./zbox copycommand to copy file to another folder path in dStorage. Only the owner of the allocation can copy an object.
By using ./zbox copy --help .You can have a look at the parameters:
Required Flags for copying the file to another folder are Allocation ID, the remote path to the existing file on dstorage, and the new destination path/folder path to copy a file to.
Steps :
Verify whether the sync.txt file is available in the remote path using list command.
./zbox list --remotepath / --allocation $ALLOC
Response:
TYPE | NAME | PATH | SIZE | NUM BLOCKS | LOOKUP HASH | IS ENCRYPTED | DOWNLOADS PAYER
+------+----------+-----------+------+------------+------------------------------------------------------------------+--------------+-----------------+
d | myfiles | /myfiles | | 4 | 0343cabc0c987686344be0b30055df76994888ce9159f97a9c76de035225fc9a | | owner
f | sync.txt | /sync.txt | 68 | 4 | 1fe7228abacc12a28277ff2fb5f97c7b7288942b8bbd7c5a96f80a1a65a0367e | NO | owner
./zbox list --remotepath /myfiles --allocation $ALLOC
Response:
TYPE | NAME | PATH | SIZE | NUM BLOCKS | LOOKUP HASH | IS ENCRYPTED | DOWNLOADS PAYER
+------+----------+-------------------+------+------------+------------------------------------------------------------------+--------------+-----------------+
f | info.txt | /myfiles/info.txt | 76 | 4 | f15383a1130bd2fae1e52a7a15c432269eeb7def555f1f8b9b9a28bd9611362c | NO | owner
f | sync.txt | /myfiles/sync.txt | 68 | 4 | 4a5669bef007b8f3b8a93e34fb9c43ab1f868701379777c2580b8196029e9923 | NO | owner
Moving Files Between Directories in dStorage
The ./zbox move command can be used to move files between folder paths in dStorage. The parameters required for the move command can be viewed using ./zbox move --help
The required parameters are Allocation ID , dest path and remote path of the moving file .
Steps:
Verify whether the directories are available in the remote path using the list command.
./zbox list --remotepath / --allocation $ALLOC
Response:
TYPE | NAME | PATH | SIZE | NUM BLOCKS | LOOKUP HASH | IS ENCRYPTED | DOWNLOADS PAYER
+------+----------+-----------+------+------------+------------------------------------------------------------------+--------------+-----------------+
d | myfiles | /myfiles | | 8 | 0343cabc0c987686344be0b30055df76994888ce9159f97a9c76de035225fc9a | | owner
f | sync.txt | /sync.txt | 68 | 4 | 1fe7228abacc12a28277ff2fb5f97c7b7288942b8bbd7c5a96f80a1a65a0367e | NO | owner
d | myfiles1 | /myfiles1 | | 4 | d541b2190c7527967ae10a8f991f34ebf9d474c10ba02832d224093110f1fcfc | | owner
As you can see there are two directory paths available /myfiles and myfiles1.We will move the info.txt file available remotepath /myfiles to the destpath/myfiles1 .
3. Verify whether the file has moved by listing the directory path using:
./zbox list --remotepath /myfiles1 --allocation $ALLOC
Response:
TYPE | NAME | PATH | SIZE | NUM BLOCKS | LOOKUP HASH | IS ENCRYPTED | DOWNLOADS PAYER
+------+-----------+---------------------+------+------------+------------------------------------------------------------------+--------------+-----------------+
f | info1.txt | /myfiles1/info1.txt | 112 | 4 | 675fab6ebfd03539848e224c2f758af33f5c8f34fb1471c9ede1fa387e389d52 | NO | owner
f | info.txt | /myfiles1/info.txt | 76 | 4 | c369ce1609ca141142ab3146b7c436d945bfa4f1dd6dda1f19820dbd71c3dfe1 | NO | owner
Renaming Files in dStorage
./zbox rename command can be used to rename files already existing in dStorage.Only the allocation's owner can rename a file. Parameters for the command can be viewed using ./zbox rename --help
TYPE | NAME | PATH | SIZE | NUM BLOCKS | LOOKUP HASH | IS ENCRYPTED | DOWNLOADS PAYER
+------+-------------------+-------------------+------+------------+------------------------------------------------------------------+--------------+-----------------+
d | myfiles | /myfiles | | 4 | 0343cabc0c987686344be0b30055df76994888ce9159f97a9c76de035225fc9a | | owner
d | myfiles1 | /myfiles1 | | 8 | d541b2190c7527967ae10a8f991f34ebf9d474c10ba02832d224093110f1fcfc | | owner
f | /myfiles/info.txt | /myfiles/info.txt | 68 | 4 | f15383a1130bd2fae1e52a7a15c432269eeb7def555f1f8b9b9a28bd9611362c | NO | owner
List files from Blobbers
./zbox listcommand is used to list all the files from a specified directory on dStorage. Use ./zbox list --help to know the possible parameters.
Command :
./zbox list --remotepath $remote --allocation $ALLOC
Sample Response :
Get Stats for file in dStorage
./zbox stats command can be used to get upload, download and challenge information for a file. Parameters for the command can be viewed using ./zbox stats --help
Steps:
Verify whether the file exists at the remote path using
./zbox list --remotepath $remote --allocation $ALLOC
Response:
TYPE | NAME | PATH | SIZE | NUM BLOCKS | LOOKUP HASH | IS ENCRYPTED | DOWNLOADS PAYER
+------+-----------+---------------------+------+------------+------------------------------------------------------------------+--------------+-----------------+
f | info1.txt | /myfiles1/info1.txt | 112 | 4 | 675fab6ebfd03539848e224c2f758af33f5c8f34fb1471c9ede1fa387e389d52 | NO | owner
f | info.txt | /myfiles1/info.txt | 76 | 4 | c369ce1609ca141142ab3146b7c436d945bfa4f1dd6dda1f19820dbd71c3dfe1 | NO | owner
./zbox meta command is used to get meta data for the given file in dStorage . Use ./zbox meta --help to know more about possible flags.
Command:
./zbox meta --remotepath $remote --allocation $ALLOC
Sample Response:
Get Download cost
./zbox get-download-cost determines the cost for downloading the remote file from dStorage. The client must either be the owner, a collaborator or be using an auth ticket.
./zbox get-upload-cost determines the cost for uploading a local file on dStorage. --duration Ignored if --end true, in which case the cost of upload calculated until the allocation expires.
./zbox get-diff command returns the differences between the local files specified by localpath and the files stored on the root remotepath of the allocation.localcache flag can also be specified to use the local cache of remote snapshot created during Sync for file comparison.
./zbox sync command is used to sync all files in the local folder. Creation, deletion and updation will be done automatically. Parameter details can be viewed using the ./zbox sync --help command.
Here are the Parameters:
Example:
Let's sync files stored in the local directory .The local directory for sync in the command below is mapped to local variable. Variable cache is marked to local cache text file located inside the local directory..
Verify whether all the files located in the local directory are synced to dStorage using
./zbox list --remotepath / --allocation $ALLOC
Batch upload files to dStorage
./zbox sync command with --uploadonly flag can be used to upload all the files in local folder to dStorage. Parameter details can be viewed using the ./zbox sync --help
Here are the Parameters:
Example:
We will create three txt files and move them into a directory to specify it as a local path for the ./zbox sync command.
Here is the list of contents of the directory:
file1.txt file2.txt file3.txt
Now by using the ./zbox sync command with --uploadonlyflag we will batch upload these files to the dStorage .Variable local is marked to local directory containing all the files for upload. Variable cache is marked to local cache text file located inside the local directory.
OPERATION | PATH
+-----------+------------+
Upload | /file1.txt
Upload | /file2.txt
Upload | /file3.txt
12 / 12 [=======================================================================================================================================================================] 100.00% 0s
Status completed callback. Type = application/octet-stream. Name = file1.txt
24 / 24 [=======================================================================================================================================================================] 100.00% 0s
Status completed callback. Type = application/octet-stream. Name = file2.txt
28 / 28 [=======================================================================================================================================================================] 100.00% 0s
Status completed callback. Type = application/octet-stream. Name = file3.txt
Sync Complete
Verify whether the files are uploaded using
./zbox list --remotepath / --allocation $ALLOC
Response:
All the files located in the local directory should be listed in the remotepath.
TYPE | NAME | PATH | SIZE | NUM BLOCKS | LOOKUP HASH | IS ENCRYPTED | DOWNLOADS PAYER
+------+-----------+------------+------+------------+------------------------------------------------------------------+--------------+-----------------+
d | myfiles | /myfiles | | 4 | e8129c2bc551226f0043b17c218f27bfaababd3e6340c60590e4edbbd9cb2517 | | owner
f | file1.txt | /file1.txt | 12 | 4 | 899454ceec5d3791f15743dfd91ce22eb9b365f1563c5e389bf3b0ca2e92f85f | NO | owner
f | file2.txt | /file2.txt | 24 | 4 | 585d0cc1fcffbf5d2c13697489eb3d49247deaebda380c60afd759b4ca15dad6 | NO | owner
f | file3.txt | /file3.txt | 28 | 4 | 63c8f593b9341873f4b5f478c49da1b6d9c58a3aefc4f483a017b86840ba0e7d | NO | owner
Private File Sharing
Private sharing of files can be implemented using the ./zbox share command.Parameters can be viewed using./zbox share --helpare shown below:
Note: Private File Sharing only works with encrypted files.
Let's consider two users (User A and B) and User A wants to privately share the info.txt file located in myfiles/info.txt directory in dStorage with User B.
2. User B has to share his client id and encryption public key which can be retrieved using thegetwalletcommand. Here we are showing the output of the UserB getwallet command
Command:
./zbox getwallet
Response:
PUBLIC KEY | CLIENTID | ENCRYPTION PUBLIC KEY
9bdb7137eab401bf715d49479fd7790a35b270ac08b23b5778fea005c81f2f19a66785bb7917830d2d
513afffc4061bc578fa9af09eb2cf17fd8a6fdb877ef8e
| 8e4e5ad06a7fef3e3810074f0f6b2d203170d0e386a84936ea5fc94428ce18c9
| qpV7bqX77UEzNj722qIrxgpHBVR5i8sR6UDdQ70ZSys=
3.Let's export the User B clientid and public encryption key to a variable named UserB and PUBLIC_KEY_UserB
4.Now use the ./zbox share command with above exported variables .Also specify the allocation and remote path for the file shared by User A which is myfiles/info.txt .
The Response provides an encrypted auth token string that only UserB can use for private download. Any other user using this AuthToken will not be able to download the file.
5.Let's use ./zbox download using Authtoken provided on UserB computer to privately download the file. Necessary Flags are Authtoken and local path to save the file. Make sure to point encrypted auth token using the export AUTH=<Auth token> before running the download command.
23 / 23 [=======================================================================================================================================================================] 100.00% 0s
Status completed callback. Type = application/octet-stream. Name = info.txt•
6.To check sharing details and verify whether the file is encrypted. You can also base decode the Authtoken using:
Private sharing of directories can be implemented using the ./zbox share command.Parameters can be viewed using./zbox share --helpare shown below:
Note: Private Directory Sharing works for both encrypted and non-encrypted files
Let's consider two users (User A and B) and User A wants to privately share the docs directory in dStorage with User B.
1.User A should check whether the docsdirectory exists on dStorage using the list command.
Command :
./zbox list --remotepath /docs --allocation c6507f3f6470972a928576a2f0cb00019fcc4ca8e60c8c9e085a8a905da6d838
Response :
TYPE | NAME | PATH | SIZE | NUM BLOCKS | LOOKUP HASH | IS ENCRYPTED | DOWNLOADS PAYER
-------+-----------+-----------------+------+------------+------------------------------------------------------------------+--------------+------------------
f | info.txt | /docs/info.txt | 48 | 4 | 3b256a3b8fbf1f497eea5b7d149228fc23e39c98c7f06b960949690070157d3b | NO
f | hello.txt | /docs/hello.txt | 30 | 3 | 4f2515f95d35c7d6641197cc024608b4dc2af1b4c8fb9af0f2637e0c89c3c5cc | NO
2. Now User B has to share his client id and encryption public key which can be retrieved using thegetwalletcommand. Here we are showing the output of the UserB getwallet command
Command:
./zbox getwallet
Response:
PUBLIC KEY | CLIENTID | ENCRYPTION PUBLIC KEY
-----------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------+-----------------------------------------------
9332ca57e335f286f1d3edc2dd7589594dbb4b30fae19766b5f67712520fde09f8eac6a979f3574ccd89e5680a6b47dcdc88ae0544dc30633cce2a7831ce0014 | 9460d64ab63340a0b4305d20a032690a495ed50d6dc92d238a42b25fdf79258b | bKodfMsHfUNXr/rr8msPe4Rv2nLP34aUIasK44p7tRs=
3.Let's export the User B clientid and public encryption key to a variable named UserB and PUBLIC_KEY_UserB
The Response provides an encrypted auth token string that only UserB can use for private download. Any other user using this AuthToken will not be able to download the file.
6. Now UserB can download files inside the shared directory with the AUTH token. First point the encrypted auth token to a variable using the export command.
19 / 19 [=====================================================================================================================================================================================] 100.00% 0s
Status completed callback. Type = application/octet-stream. Name = docs
Note : The allocation ID required in the command above can be retrieved from decoding the AUTH string. For remote path the actual path for the shared directory should be specified.
If you are not able to download files and getting Error in file operation: File content didn't match with uploaded file response check Error 2 in Tips and Troubleshooting Section.
Repair a file on dStorage
Use ./zbox start-repair command to repair a file on dStorage. Parameters can be viewed using the --help flag.
In the above response the total number of files repaired were 0 which means all the data blocks for the files are not altered or damaged.
Rollback
Use ./zbox rollback to rollback to a previous state of allocation. This is helpful when you want to rollback to previous version of files you updated on allocation using Update allocation.
Sample Command:
./zbox rollback --allocation $ALLOCATION_ID
Sample Response:
Rollback successful
Total Stored Data
./zbox total-stored-data returns the summation of all the Size fields in all the files stored across blobbers.
Sample Command:
./zbox total-stored-data
Sample Response:
total stored data: 673504
Asking the receiver to pay for download (RX_pay)
RX pay is a specified boolean flag in ./zbox download command which asks the file receiver to pay for their file download.
Parameters for --rx_pay flag can be viewed using the zbox download --help.
As we can see that RX pay requires download by auth ticket and a rx_pay boolean set to true .
Example: Let's take two users (User A and User B). User A is the seller of the file downloaded by User B (receiver).
1.User A will upload a file on dstorage and share an authtoken for the file. For example we are uploading
info1.txt file located on myfiles directory of dStorage which User B will download and pay for himself using --rxpay.
2.To make the file available for pay User A has to set the--attr-who-pays-for-reads for upload command to 3rd_party (by default it is set to "owner")
3.To verify whether downloads payer are properly configured use:
./zbox list --remotepath $remote --allocation $ALLOC
Response:
TYPE | NAME | PATH | SIZE | NUM BLOCKS | LOOKUP HASH
| IS ENCRYPTED | DOWNLOADS PAYER
f | info1.txt | /myfiles/info1.txt | 44 | 4 | bf58c1b39eb26ae8762822623
e38f919358338017f8b2144e5cf6ccab23fd2af | NO | 3rd_party
In the response, you will notice that the downloads payers section for info1.txt are successfully set to 3rd-party.
4.To know how to share a file on dStorage and get an AuthToken for a file have a look at the sharing a file on dStorage .
5.Once the auth token is created and marked to a variable, share it with the receiver(UserB) who will run the .zbox download command to download the file with --rx_pay flag.
23 / 23 [=======================================================================================================================================================================] 100.00% 0s
Status completed callback. Type = application/octet-stream. Name = info1.txt
To verify whether (UserB) has paid successfully for the download check the wallet and read pool balance for change using ./zwallet getbalance and /zbox rp-info.
Note: Do unlock read tokens using rp-unlock before using ./zwallet getbalanceto let the download money reflect in wallet.
Video Streaming
Video streaming with Zboxcli can be implemented with players for different operating platforms(iOS, Android, Mac). Zbox CLI does not have a player itself and uses the following helping functions :
downloadFileByBlocks - properly returns file-chunks with correct byte range,.
getFileMeta - returns actuaBlockNumbers and actualFileSize (exclude thumbnail size)
getFileMetaByAuth - same updates as getFileMeta
listAllocation - returns actuaBlockNumbers and actualFileSize (exclude thumbnail size)
For all the Platforms streaming implementation using ZboxCLi has the following flow:
When the user starts the video player (ExoPlayer for Android or AVPlayer for iOS), A ZChainDataSource starts chunked download and requests chunks of video from the buffer(a Middleman between streaming player and Zbox).
After the arrival of the first chunk, the player starts requesting more chunks from the buffer which request the Zbox SDK .Zbox SDK which is built using GO makes use of the downloadFileByBlocks method to reliably download large files by chunking them into a sequence of parts that can be downloaded individually. Once the blocks are downloaded they are read into input streams and added to the media source of the streaming player.
The task of downloading files and writing them to buffer using ZboxSDK happens constantly and If player request random bits of video they are delivered instantly by the buffer.
In a case, if the player didn't receive chunks (for example it's still not downloaded), then the player switches to STALE state and the video stream will pause. During the STALE state, player tries to make multiple requests for chunks, if didn't receive a response the video stream stops.
To understand how Zbox CLI provides downloading of files by blocks check the below demonstration:
For instance, Let's consider an allocation which has a audio.mp3file stored on dStorage. Make sure the file has a large size(more than 64 kB(64000 bytes) ) to download the file by blocks. The size and other attributes of the sampleaudio.mp3file can be viewed using
./zbox list --allocation $ALLOC --remotepath /myfiles
Response:
TYPE | NAME | PATH | SIZE | NUM BLOCKS |LOOKUP HASH
| IS ENCRYPTED | DOWNLOADS PAYER
+------+-----------+--------------------+---------+------------+----------------
f | audio.mp3 | /myfiles/audio.mp3 | 5992396 | 92 | 3cea39505cc30fb9f6fc5c6045284188feb14eac8ff3a19577701c4f6d973239
| NO | owner
Here we can see audio.mp3 file has size (5993286) bytes and has 92 blocks. If we want to download a certain number of blocks for the info.txt file we can use --endblock or --startblock flag with ./zbox download command. Other flags for download can be viewed using ./zbox download --help
To download only 3 blocks of audio.mp3 file we specify --startblock and--endblock with an integer value of 1 and 3. --blockspermarkerflag can also be specified to download multiple blocks at a time(default is 10).
The whole download command for downloading till 3rd block of audio.mp3 file would be: