Upload a File

Now that you have a bucket to put files in, you are ready to upload a file.

List buckets will show you the bucket ID you need to upload files:

$ b2 list_buckets
10f72c8d00b1ea614ceb0319 allPublic KittenPhotos

If you have a local file on your computer called "kitten.jpg" and you want to upload this file to your "KittenPhotos" bucket into a folder named "fluffy", you would do it like this:

$ b2 upload_file KittenPhotos kitten.jpg fluffy/kitten.jpg
    "accountId": "78fd8b566fb6", 
    "bucketId": "10f72c8d00b1ea614ceb0319", 
    "contentLength": 4877, 
    "contentSha1": "3a16e5f24a9a4e8a47438f39141ec33a79bd97bc", 
    "contentType": "text/jpeg", 
    "fileId": "4_z10f72c8d00b1ea614ceb0319_f10072d5b729d51d1_d20150731_m214727_c100_v0009990_t0004", 
    "fileInfo": {}, 
    "fileName": "fluffy/kitten.jpg"

The ls command will show the files in your bucket:

$ b2 ls KittenPhotos

Once the file is uploaded, you can download it using the download_url that was returned by b2_authorize_account. Starting with the download_url, add the bucket name and the file name to make the complete URL, which you can put in your web browser to view the photo you just uploaded:


See b2_download_file_by_id and b2_download_file_by_name for more details on downloading files.