Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何创建用于将图像上载到Azure存储Blob的Web服务?_C#_Android_Asp.net_Web Services_Azure Storage Blobs - Fatal编程技术网

C# 如何创建用于将图像上载到Azure存储Blob的Web服务?

C# 如何创建用于将图像上载到Azure存储Blob的Web服务?,c#,android,asp.net,web-services,azure-storage-blobs,C#,Android,Asp.net,Web Services,Azure Storage Blobs,我正试图上传一张我从安卓设备上获得的图像作为ByteArray 到我的Azure存储Blob。通过在asp.net中使用Web服务 但我不知道怎么做 以下是我目前的代码: [WebMethod] public string UploadFile(byte[] f, string fileName) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse( Configur

我正试图上传一张我从安卓设备上获得的图像作为ByteArray

到我的Azure存储Blob。通过在asp.net中使用Web服务

但我不知道怎么做

以下是我目前的代码:

[WebMethod]

    public string UploadFile(byte[] f, string fileName)
    {

        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
        ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);

        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 "filename...".
        CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName);

        // Create or overwrite the "filename..." blob with contents from a local file.
        using (var fileStream = System.IO.File.OpenRead("C:\\filepath"))
        {
            blockBlob.UploadFromStream(fileStream);
        }

        return "OK";
    }
这段代码从我计算机上的本地文件路径获取图像,这不是我想要的

我想使用从Android设备接收的字节[]数组“f”而不是“C:\filepath”


我该怎么做?

您在哪里使用了
字节[]f
?还是我漏掉了什么?对不起,我漏掉了最后一句话!您需要将字节数组写入流,类似于使用(FileStream f=File.Open(@“C:\Test.txt”){f.write(buff,0,buff.Length);}我是这样做的:使用(var stream=new MemoryStream(f,writable:false)){blockBlob.UploadFromStream(stream)}这看起来正确吗?我现在没有Azure的访问权限,因此无法提供工作代码。但我认为你展示的代码应该是有效的。你试过了吗?