1. Home
  2. Docs
  3. BangDB 2.0 REST API
  4. API 2.0
  6. Download/get a file from the bucket

On this page

Download/get a file from the bucket

Method : POST
URI : /brs/<bucket_name>/gettfile

Body : json doc

workflow to download a file name “aloi” which is present in the bucket “mybucket”

STEP1 : Send a request that you are intending to download the file named “aloi”

POST /brs/mybucket/getfile
"access_key": "brs_access_key",
"secret_key": "brs_secret_key",
"bucket_name": "mybucket",
"key": "aloi"

The db will send the following response

"next_key": "aloi:0:17:17254154:1641803297543410",
"nslice": 17,
"chunk_size": 1048576,
"file_size": 17254154,
"next_id": 0

This tells that file “aloi” is present in the bucket and its size is ~17MB, stored in 17 slices where each slice has chunk size of 1MB
Now we need to start a loop to get all the content, db will keep helping with the next_key that should be used

• STEP2: first request will be POST request /brs/mybucket/getfile?key=<next_key>&nslice=<nslice> . The body dummy, “dummy”
for example /brs/mybucket/getfile?key= aloi:0:17:17254154:1641803297543410&nslice=17

STEP2: Repeat nslice times

• set counter i = 1
• POST request /brs/mybucket/getfile?key=aloi:i&nslice=17 . The body dummy, “dummy”
• The server will send response which is base64 encoded chunk of 1MB size
• Decode the data and write to the end of the file (download file)
• if error occurs – quit
• set i = i+1 and goto beginning of step 2

Note: since we download encoded text as chunks hence we must set the right Content-type in the request header. The Content-type should be plain/text [ “Content-type :plain/text” ]
Again if you use BangDB CLI or dashboard, these steps are abstracted and you simply run the download or upload command

Was this article helpful to you? Yes No