For private B2 buckets, downloads require authorization. A download authorization token can be limited to files whose names begin with a specified prefix and can be included with a download request. This is a bearer credential: anyone who receives it can use it within its scope and lifetime.
Before You Begin
- A private B2 bucket and a standard application key with the required read/share capabilities.
- A server-side process that authenticates the requesting user and checks file access.
- A predictable file naming or prefix strategy.
Recommended Approach
1. Authorize the account
Use the B2 authorization API with a restricted application key. Keep the key ID and application key on the server and protect the returned account authorization token.
2. Request download authorization
Call the download-authorization operation for the narrowest filename prefix and a short validity period that fits the task. Do not request authorization for an entire bucket if one file or folder prefix is sufficient.
3. Build the download request
Use the correct B2 download URL and include the authorization token as required by the API. URL-encode file names and ensure that the token is not accidentally stripped by a proxy or CDN.
4. Authorize the user before issuing the URL
Your application must check that the logged-in user is entitled to the requested file before returning a download URL or token. B2 token scope is not a replacement for your application’s user-level authorization.
5. Protect and expire the link
Use HTTPS, short validity, no-store caching where appropriate, and avoid logging full token-bearing URLs. Test expiration and attempts to download files outside the authorized prefix.
Operational Considerations
Cloud storage and compute designs should account for security, availability, lifecycle, and cost together. Decide where data resides, how long it is retained, which identities can reach it, and how the service behaves during a regional or credential failure. Separate production and test resources when their access needs differ. Review data-transfer charges, request volume, version retention, and abandoned multipart uploads as part of routine operations.
How to Verify the Result
Test the workflow using the same role and network path that the deployed application will use. Verify successful access to the intended object or service, denial for an unrelated object, and behavior after a temporary credential expires. Check logs for the principal and operation, and confirm that lifecycle, versioning, and backup settings match the data-retention policy.
Example Configuration
Illustrative example — adapt values to your environment
# Conceptual flow
1. User requests file from your application.
2. Server verifies user permission.
3. Server obtains narrow B2 download authorization.
4. Browser downloads using the temporary authorization token.
Common Mistakes to Avoid
- A prefix token can authorize more than one file; choose prefixes carefully.
- Do not expose the application key or account authorization token in browser source.
- Do not assume a token is one-time-use; enforce one-time downloads in your own application if required.
Make one change at a time, test it from the perspective of the actual user or application, and record the reason for the change. Keep a rollback path for network, identity, and production configuration changes.
Final Checklist
- The configuration matches the intended environment and service version.
- Access is limited to the required identities, resources, ports, and operations.
- The expected workflow has been tested, including a negative test for unauthorized access.
- Secrets and temporary credentials are protected and excluded from logs and source control.
- The configuration owner, purpose, and review or expiration date are documented.