GithubHelp home page GithubHelp logo

azure-samples / storage-blob-android-photo-uploader Goto Github PK

View Code? Open in Web Editor NEW
10.0 27.0 13.0 95 KB

Getting started sample for Adroid that show how to upload and retrieve photos/images from the Azure Blob Storage

License: MIT License

Java 100.00%

storage-blob-android-photo-uploader's Introduction

services platforms author
storage
android
pcibraro

Azure Storage Service - Photo Uploader Sample for Android

This sample demostrates how to upload photo images from the gallery in Android into a Block Blob in Azure Storage. It shows different buttons for performing actions such as selecting an image from the gallery, uploading an image to the blob storage or listing all the uploaded images.

Note: This is a project for Android Studio, which uses Gradle and references the Microsot Azure Storage Library for Android available in the Central Maven Repository. Also, it runs against the actual service, so it is highly recommended that you use a test container, as you will be creating and deleting actual blobs.

Running this sample

  1. Open the solution with Android Studio.
  2. Open the ImageManager.java file and change the "[ACCOUNT_NAME]" and "[ACCOUNT_KEY]" in the storageConnectionString variable with account and key provided in the Azure Portal.

WARNING: Only use Shared Key authentication for testing purposes! Your account name and account key, which give full read/write access to the associated Storage account, will be distributed to every person that downloads your app. This is not a good practice as you risk having your key compromised by untrusted clients. Please consult following documents to understand and use Shared Access Signatures instead. https://docs.microsoft.com/en-us/rest/api/storageservices/delegating-access-with-a-shared-access-signature and https://docs.microsoft.com/en-us/azure/storage/common/storage-dotnet-shared-access-signature-part-1

More information

storage-blob-android-photo-uploader's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

storage-blob-android-photo-uploader's Issues

Wrong SAS was generated with blob storage SDK for Android

1, iOS SDK SAS is correct:
?se=2018-11-14T02%3A44%3A04Z&sr=b&sp=r&sv=2015-04-05&sig=1iOkA%2BdAZTbF4%2F36uHrC8QT0pi9dIpVC4ma%2F2uxfPrY%3D&spr=https&st=2018-11-13T02%3A44%3A04Z

2, Android SDK SAS is wrong:
sig=KKL9qqSLceaRBGkTWjRQKC6XnhJ5%2FSNsZ6Sqsdc8cSU%3D&st=2018-11-13T03%3A02%3A16Z&se=2018-11-14T03%3A02%3A16Z&sv=2017-04-17&sr=b
(1) missing sp=r
(2) missing spr=https

Null pointer expcetion at CloudBlobContainer container = blobClient.getContainerReference("testcontainer");

am getting null pointer exception at CloudBlobContainer container = blobClient.getContainerReference("testcontainer");

logs as below -

W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
2019-01-16 18:33:21.746 23922-24183/com.microsoft.photouploader W/System.err: at com.microsoft.azure.storage.core.Utility.isHostDnsName(Utility.java:404)
2019-01-16 18:33:21.746 23922-24183/com.microsoft.photouploader W/System.err: at com.microsoft.azure.storage.core.Utility.determinePathStyleFromUri(Utility.java:392)
2019-01-16 18:33:21.746 23922-24183/com.microsoft.photouploader W/System.err: at com.microsoft.azure.storage.StorageUri.(StorageUri.java:71)
2019-01-16 18:33:21.746 23922-24183/com.microsoft.photouploader W/System.err: at com.microsoft.azure.storage.core.PathUtility.appendPathToUri(PathUtility.java:123)
2019-01-16 18:33:21.747 23922-24183/com.microsoft.photouploader W/System.err: at com.microsoft.azure.storage.core.PathUtility.appendPathToUri(PathUtility.java:108)
2019-01-16 18:33:21.747 23922-24183/com.microsoft.photouploader W/System.err: at com.microsoft.azure.storage.blob.CloudBlobContainer.(CloudBlobContainer.java:205)
2019-01-16 18:33:21.747 23922-24183/com.microsoft.photouploader W/System.err: at com.microsoft.azure.storage.blob.CloudBlobClient.getContainerReference(CloudBlobClient.java:133)
2019-01-16 18:33:21.747 23922-24183/com.microsoft.photouploader W/System.err: at com.microsoft.photouploader.ImageManager.getContainer(ImageManager.java:57)
2019-01-16 18:33:21.748 23922-24183/com.microsoft.photouploader W/System.err: at com.microsoft.photouploader.ImageManager.UploadImage(ImageManager.java:63)
2019-01-16 18:33:21.748 23922-24183/com.microsoft.photouploader W/System.err: at com.microsoft.photouploader.MainActivity$4.run(MainActivity.java:101)
2019-01-16 18:33:21.748 23922-24183/com.microsoft.photouploader W/System.err: at java.lang.Thread.run(Thread.java:764)

In slow network uploading video file in azure server throwing Exception

I am trying to upload video file of 10-11 MB on azure server.It working fine on 4g or wifi network.But it is throwing below error on 3g or 2g network.

Getting exception :--

java.io.IOException: The client could not finish the operation within specified maximum execution timeout. Please see the cause for further information

Below is my code :--

`try {
        // Setup the cloud storage account.
        CloudStorageAccount account = CloudStorageAccount
                .parse("somestring");

        // Create a blob service client
        CloudBlobClient blobClient = account.createCloudBlobClient();
        BlobRequestOptions uploadOptions = new BlobRequestOptions();
        uploadOptions.setMaximumExecutionTimeInMs(300000);
        uploadOptions.setTimeoutIntervalInMs(100000);
        RetryPolicy retryPolicy=new RetryExponentialRetry(
                60000 /* minBackoff in milliseconds */,
                30000 /* delatBackoff in milliseconds */,
                180000 /* maxBackoff in milliseconds */,
                3 /* maxAttempts */);
        uploadOptions.setRetryPolicyFactory(retryPolicy);
        // Get a reference to a container
        // The container name must be lower case
        // Append a random UUID to the end of the container name so that
        // this sample can be run more than once in quick succession.
        CloudBlobContainer container = blobClient.getContainerReference("videos");

        // Create the container if it does not exist
        container.createIfNotExists();

        // Make the container public
        // Create a permissions object
        BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
        OperationContext opContext = new OperationContext();
        StorageEventMultiCaster storageEventMultiCaster = new StorageEventMultiCaster<>();

        // Include public access in the permissions object
        containerPermissions
                .setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
        storageEventMultiCaster.addListener(new StorageEvent<SendingRequestEvent>() {

            @Override
            public void eventOccurred(SendingRequestEvent eventArg) {

                // Do custom monitoring here...
            }
        });
        opContext.setSendingRequestEventHandler(storageEventMultiCaster);
        // Set the permissions on the container
        container.uploadPermissions(containerPermissions);
        CloudBlockBlob blob = container.getBlockBlobReference(file.getName());

        byte[] buffer = IOUtils.toByteArray(new FileInputStream(file));
        ByteArrayInputStream  inputStream = new ByteArrayInputStream(buffer);
        blob.upload(inputStream, inputStream.available(),null,uploadOptions,opContext);
        inputStream.close();
        String url = blob.getUri().toString();
                } catch (Throwable t) {

    }`

More information is available on https://stackoverflow.com/questions/47793540/in-slow-network-uploading-video-file-in-azure-server-throwing-timeoutexception/47793942

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.