Azure / azure-storage-android

Microsoft Azure Storage Library for Android
Apache License 2.0
81 stars 48 forks source link

SAS token blob container Shared Key authentication #78

Closed psioukas closed 4 years ago

psioukas commented 4 years ago

Hello, I was wondering what are the steps, for using a Share key authentication, instead of providing the account name and key to each user. I am trying to use this library to share files between several users. Can we have more detailed examples for this situations?

gadeweever commented 4 years ago

See: Issue 16

The last comment has an example in Kotlin using an AsyncTask instance.

psioukas commented 4 years ago

See: Issue 16

The last comment has an example in Kotlin using an AsyncTask instance.

Thank you ! :)

psioukas commented 4 years ago

image I tried it this way and it worked. Thank you


 // Get SAS token from Azure Storage Explorer after creating permissions for a Blob Container , create an instance of StorageCredentialsSharedAccessSignature using the SAS token.
                StorageCredentialsSharedAccessSignature SAS_TOKEN = new StorageCredentialsSharedAccessSignature("sas_token_permissions_from_storage_explorer");
try {
  container = new CloudBlobContainer(URI.create("https://'account_name'.blob.core.windows.net/'blob_Container_name'"),SAS_TOKEN);

CloudBlockBlob blockBlob = container.getBlockBlobReference(fileName+fileType);

//   Same file are overwritten. Using the following if statement it creates a new file.
if (blockBlob.exists()){             
blockBlob=container.getBlockBlobReference(Calendar.getInstance().getTime()+"_"+file.getName());
}
//Upload file.
 blockBlob.uploadFromFile(stringFilePath,null,null,null);
 } catch (StorageException e) {
      e.printStackTrace();
  } catch (URISyntaxException e) {
       e.printStackTrace();
  } catch (IOException e) {
       e.printStackTrace();
  }
AdrianxSh commented 3 years ago

@saio23 Thanks dude, this worked for me too.