简体   繁体   中英

Backblaze Storage B2 PHP Download with Authorization from Private Bucket

I'm sort of struggling to understand the documentation for BackBlaze B2, I want to download files from a private bucket using PHP, I know the file ID and I want to get authorization (like 30 seconds) and then generate a download link (Presigned?).

  1. b2_authorize_account
  2. b2_get_download_authorization
  3. b2_download_file_by_name

I'm just not quite sure how to put the example codes all together, pardon my ignorance.

https://www.backblaze.com/b2/docs/downloading.html

I spent a while looking for the answer to this as well. Apparently it is possible.

Essentially the steps are as follows:

  1. On the server, make a GET request to the b2_authorize_account endpoint, to get an auth token ( https://www.backblaze.com/b2/docs/b2_authorize_account.html )
  2. Also on the server, make a POST request to the b2_get_download_authorization endpoint to get a more specific auth token used just for downloading ( https://www.backblaze.com/b2/docs/b2_get_download_authorization.html )
  3. Form the download URL by combining the apiUrl from step 1, with the path to the specific file, and then appending the token from step 2 as a query param (this is the part that's very difficult to find in their documentation).
  4. Send the download URL out to the browser, and the user can click it to access the file.

So you'll get something like https://api001.backblazeb2.com/file/bucket-name/path/to/file?Authorization={token}

You can restrict the length of time that the auth token is valid, and restrict it so that only files which have a particular prefix can be accessed. So if you want to make a particular private file available to a particular user that you've already authenticated, you can use these steps to generate a token with a short lifetime that only works for the specific file (by using the full file name as the prefix).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM