Backblaze / b2-sdk-java

The official Java SDK for using Backblaze's B2 Storage APIs
Other
94 stars 25 forks source link

getBucketOrNullByName() results in 401 response of a key is limited to that bucket #151

Closed skand888 closed 3 years ago

skand888 commented 3 years ago

This is because this function tries to list all buckets instead of using the bucketName option of the B2ListBucketsRequest

    default B2Bucket getBucketOrNullByName(String name) throws B2Exception {
        for (B2Bucket bucket : buckets()) {
            if (bucket.getBucketName().equals(name)) {
                return bucket;
            }
        }
        return null;
    }

According to B2 documentation: "If you ask for all buckets and your application key is restricted to one bucket, the call is unauthorized."

The workaround is to call listBuckets() with the bucket name as an option instead of getBucketOrNullByName().

ericjding commented 3 years ago

Fixed in #152