Can I upload a stream to Azure blob storage without specifying its length upfront?

前端 未结 1 1951
借酒劲吻你
借酒劲吻你 2021-01-12 09:12

I don\'t know if it\'s relevant, but I am using Java with the azure-storage-android-0.2.0.aar for the upload.

I can upload files to Microsoft Azure blob storage

相关标签:
1条回答
  • 2021-01-12 09:28

    We’ll log feature request to enable uploading from a stream without specifying length. For now, you may want to use the openOutputStream method which has a write method taking a byte[] or an int. An example using the int method is below:

        CloudBlockBlob blockBlob = container.getBlockBlobReference(‘myblob’); // assuming container was already created
    
        BlobOutputStream blobOutputStream = blockBlob.openOutputStream();
        ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer); // assuming buffer is a byte[] with your data
    
        int next = inputStream.read();
        while (next != -1) {
              blobOutputStream.write(next);
              next = inputStream.read();
        }
    
        blobOutputStream.close();
    
    0 讨论(0)
提交回复
热议问题