是否可以在不预先指定流长度的情况下将流上传到Azure blob存储? [英] Can I upload a stream to Azure blob storage without specifying its length upfront?

查看:50
本文介绍了是否可以在不预先指定流长度的情况下将流上传到Azure blob存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道它是否相关,但是我正在将Java与azure-storage-android-0.2.0.aar一起上传.

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.

我可以将文件上传到Microsoft Azure Blob存储

I can upload files to Microsoft Azure blob storage

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

其中n是从文件派生的inputStream的长度.

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

这是我的问题:我想直接从相机进行流式传输,例如,这显然是不可能的,因为Azure要求上传的长度参数,但仍在流式传输时未知.

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.

我为什么需要指定长度? (MD5?)还有一种方法可以在仍在生成流的同时进行上传(这显然是Java中的InputStream的概念,这是InputStream不具有length属性的原因)?

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)?

推荐答案

我们将记录功能请求,以允许从流中上传而无需指定长度.现在,您可能需要使用openOutputStream方法,该方法具有一个采用byte []或int值的写方法.下面是使用int方法的示例:

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();

这篇关于是否可以在不预先指定流长度的情况下将流上传到Azure blob存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆