Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

CloudBlockBlob blob = container.getBlockBlobReference("filename.ext");
blob.upload(inputStream, n);

where n is the length of the inputStream when it is derived from the file.

Here's my problem: I would like to stream directly, for example from the camera, which apparently isn't possible as Azure requires the length parameter for the upload, which is unknown while still streaming.

Is there a reason why I need to specify the length? (MD5?) And is there a way to upload while the stream is still being produced (which obviously is the idea of an InputStream in Java, the reason why InputStream does not have a length property)?

like image 356
Oliver Hausler Avatar asked Jul 07 '14 19:07

Oliver Hausler


People also ask

What storage tier is used for a blob that is uploaded once every 30 days on average?

Data in the Cool tier should be stored for a minimum of 30 days. The Cool tier has lower storage costs and higher access costs compared to the Hot tier.

Is azure Blob Storage ideal for streaming video and audio?

The correct answer is option A (Blob). Blob storage type should be used for streaming audio and video files. Azure Blob storage is mainly used for unstructured large files such as audio, video, images, backup files, etc.

What is the maximum size of blob in azure?

The maximum size of a block blob is 200 GB. But by utilizing striping, the maximum size of an individual backup can be up to 12 TB.


1 Answers

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();
like image 67
Emily Gerner Avatar answered Sep 21 '22 18:09

Emily Gerner