Using asp.net WebService & Android to upload Image to Azure Blob Storage?

旧时模样 提交于 2019-12-06 06:21:17

Finally I solved the problem :D wihu!

In the WebService I had to change:

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
ConfigurationManager.GetSetting("StorageConnectionString"));

to this(almost the same):

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));

and then go to => 'Manage nuget packages' in VS12, and install Windows Azure Storage.

Further more I had to move the variable: byte[] f = Convert.FromBase64String(myBase64String);

outside of the method, like this:

    byte[] f;
    [WebMethod]
    public string UploadFile(string myBase64String, string fileName)
    {
         f = Convert.FromBase64String(myBase64String);
    }

And that was it.

So the WebService look like this:

byte[] f;
    [WebMethod]
    public string UploadFile(string myBase64String, string fileName)
    {
        f = Convert.FromBase64String(myBase64String);


        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
        CloudConfigurationManager.GetSetting("StorageConnectionString"));

        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
        // Retrieve a reference to a container. 
        CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");

        // Create the container if it doesn't already exist.
        container.CreateIfNotExists();

        container.SetPermissions(
         new BlobContainerPermissions
         {
             PublicAccess = BlobContainerPublicAccessType.Blob
         });

        // Retrieve reference to a blob named "myblob".
        CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName);

        using (MemoryStream stream = new MemoryStream(f))
        {
            blockBlob.UploadFromStream(stream);
        }
        return "OK";
    }

This will send the image as a ByteArray to the Windows Azure Storage.

Next step is to download the file and convert it to a Bitmap image :)

If this was helpfull please give me some points :D

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!