Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example needed to use sas for uploading image file #16

Open
ShreyashPromact opened this issue Aug 7, 2015 · 5 comments
Open

example needed to use sas for uploading image file #16

ShreyashPromact opened this issue Aug 7, 2015 · 5 comments

Comments

@ShreyashPromact
Copy link

Hello, I have check your repo. That is more about to upload blob and text file to azure storage server.
I have seen your one of the document here that says that you can also use sas to upload the file.

https://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-shared-access-signature-part-2/#part-2-create-a-console-application-to-test-the-shared-access-signatures

Here in one of my client has created method from which i got sas. Now i have to use that sas to upload the file. But i am not getting proper step or way ti use it.

I need some more information on this, If possible i also want to have your repo to be updated with the example of uploading file using sas.

Thanks.

Sincerely,
Shreyash

@ShreyashPromact
Copy link
Author

I have put question here in below SO link. So if any of your contributor can also reply me over there.
http://stackoverflow.com/questions/31847102/upload-file-with-azure-storage-using-sas-shared-access-signature

@intelligear
Copy link

@ShreyashPromact
Hi, here is how I use the SAS token:
StorageCredentialsSharedAccessSignature SAS = new StorageCredentialsSharedAccessSignature(MainActivity.sasToken);
CloudBlobContainer container = new CloudBlobContainer(SAS.transformUri(new URI("https:///")));

And I guess you can directly pass the blob's URI to the transformUri rather than construct the container first.
Also you can refer to the unit tests for more usage examples.

@ShreyashPromact
Copy link
Author

@colorfulben

Thanks for your response. I really appreciate it. I suggest to put/update one example of using SAS for uploading image file because with in your git example code it is mention to upload image file using storage method and key. Now, if there is no example give to use sas to upload image file then people might get confuse about how to use it.

Thanks.

Sincerely,
Shreyash

@hfarhanahmed
Copy link

String blobUri = "https://mydomain.blob.core.windows.net/container1/container2/"+blobName;
StorageCredentialsSharedAccessSignature SAS = new StorageCredentialsSharedAccessSignature(blobToken);
CloudBlockBlob cloudBlockBlob = new CloudBlockBlob(URI.create(blobUri),SAS);
cloudBlockBlob.uploadFromFile(imagePath);

This worked for me in Android

@gadeweever
Copy link

gadeweever commented Feb 24, 2020

This still works today in Kotlin:

    private class InitializeUploadTask : AsyncTask<File, Void, Unit>() {

        override fun doInBackground(vararg input: File?) {
            try {
                val storageCredentials = StorageCredentialsSharedAccessSignature("<your token>")
                val blockBlob = CloudBlockBlob(URI.create("https://<your host name>/<your container name>/${input[0]?.name}"), storageCredentials)
                return blockBlob.uploadFromFile(input[0]?.absolutePath)
            }
            catch (e: Exception)
            {
                Log.i("MANAGER", "unexpected")
            }
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants