Backblaze / b2-sdk-java

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

Creating Keys with File Name Prefix and Single Bucket Access #105

Closed ghost closed 4 years ago

ghost commented 4 years ago

I'm having trouble figuring out how to create an account key with filename prefix and single bucket access. I've looked thru the examples, where did I miss it?

bwbeach commented 4 years ago

A command like this will do it:

b2 create-key --duration 86400 --bucket my-bucket --namePrefix photos/ test-key readFiles,writeFiles
ghost commented 4 years ago

Hey!

So that’s not possible to do with the JavaSDK? Or it is and I need to pass in parameters I’m not seeing?

When I build a key I can select permissions but I can’t seem to do anything else. I’m missing something obviously.

On Mar 4, 2020, at 13:33, Brian Beach notifications@github.com wrote:

 A command like this will do it:

b2 create-key --duration 86400 --bucket my-bucket --namePrefix photos/ test-key readFiles,writeFiles — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

certainmagic commented 4 years ago

Hi Peter --

Ooops! Although he's awesome in any language, BrianB usually responds to the CLI questions. :)

You should be able to do something like this:

final B2StorageClient b2StorageClient = /* however you get your client */;
final String bucketId = "bucket-id";
final Set<String> capabilities = new TreeSet<>();
capabilities.add(B2Capabilities.READ_FILES);
capabilities.add(B2Capabilities.WRITE_FILES);
final B2CreateKeyRequest request = B2CreateKeyRequest.builder(capabilities,"key-name")
        .setBucketId(bucketId)
        .setNamePrefix("/only/with/this/prefix/")
        .setValidDurationInSeconds(86400L)
        .build();
b2StorageClient.createKey(request);

ttfn, ab

ghost commented 4 years ago

Thank you!!!

That’s exactly what I was looking for. Cheers!

On Mar 5, 2020, at 14:04, certainmagic notifications@github.com wrote:

 Hi Peter --

Ooops! Although he's awesome in any language, BrianB usually responds to the CLI questions. :)

You should be able to do something like this:

final B2StorageClient b2StorageClient = ids.getB2StorageClient(); final String bucketId = "bucket-id"; final Set capabilities = new TreeSet<>(); capabilities.add(B2Capabilities.READ_FILES); capabilities.add(B2Capabilities.WRITE_FILES); final B2CreateKeyRequest request = B2CreateKeyRequest.builder(capabilities,"key-name") .setBucketId(bucketId) .setNamePrefix("/only/with/this/prefix/") .setValidDurationInSeconds(86400L) .build(); b2StorageClient.createKey(request); ttfn, ab

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

certainmagic commented 4 years ago

Great! Glad to hear it. :)