Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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
Azure 关于BlobRequest.PutBlock方法_Azure_Blob - Fatal编程技术网

Azure 关于BlobRequest.PutBlock方法

Azure 关于BlobRequest.PutBlock方法,azure,blob,Azure,Blob,我想知道如何形成Blobrequest.PutBlock(Uri、int timeout、string blockid、string leaseid) 当用户试图上传像100MB这样的大文件时,我会将它们分成内存中4MB的块(将4MB数据读入字节[]) 如何使用BlobRequest.PutBlock和BlobRequest.PutBlockList将传入的文件流拆分为块并上载到blob 因为我有与blob关联的租约。如果我需要使用可用的Azure SDK 1.7.0拆分文件并上载租约id为的区

我想知道如何形成Blobrequest.PutBlock(Uri、int timeout、string blockid、string leaseid)

当用户试图上传像100MB这样的大文件时,我会将它们分成内存中4MB的块(将4MB数据读入字节[])

如何使用BlobRequest.PutBlock和BlobRequest.PutBlockList将传入的文件流拆分为块并上载到blob 因为我有与blob关联的租约。如果我需要使用可用的Azure SDK 1.7.0拆分文件并上载租约id为的区块,我想这是唯一的选项

问候,,
Vivek

调用时,只需将leaseId作为最后一个参数传递:

如果您有一个CloudBlob(),那么URL很容易构建:


调用时,只需将leaseId作为最后一个参数传递:

如果您有一个CloudBlob(),那么URL很容易构建:


您可以在block:

我在这里复制代码以删除外部依赖项:

 protected void btnUpload_Click(object sender, EventArgs e)
{
    CloudBlobClient blobClient;
    var storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
    blobClient = storageAccount.CreateCloudBlobClient();

    CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");
    container.CreateIfNotExist();

    var permission = container.GetPermissions();
    permission.PublicAccess = BlobContainerPublicAccessType.Container;
    container.SetPermissions(permission);

    string name = fu.FileName;
    CloudBlockBlob blob = container.GetBlockBlobReference(name);

    blob.UploadFromStream(fu.FileContent);

    int maxSize = 1 * 1024 * 1024; // 4 MB

    if (fu.PostedFile.ContentLength > maxSize)
    {
        byte[] data = fu.FileBytes; 
        int id = 0;
        int byteslength = data.Length;
        int bytesread = 0;
        int index = 0;
        List<string> blocklist = new List<string>();
        int numBytesPerChunk = 250 * 1024; //250KB per block

        do
        {
            byte[] buffer = new byte[numBytesPerChunk];
            int limit = index + numBytesPerChunk;
            for (int loops = 0; index < limit; index++)
            {
                buffer[loops] = data[index];
                loops++;
            }
            bytesread = index;
            string blockIdBase64 = Convert.ToBase64String(System.BitConverter.GetBytes(id));

            using (var ms = new MemoryStream(buffer, true))
              blob.PutBlock(blockIdBase64, ms, null);
protectedvoidbtnupload\u单击(对象发送方,事件参数e)
{
CloudBlobClient blobClient;
var storageAccount=CloudStorageAccount.FromConfigurationSetting(“DataConnectionString”);
blobClient=storageAccount.CreateCloudBlobClient();
CloudBlobContainer container=blobClient.GetContainerReference(“mycontainer”);
container.CreateIfNotExist();
var permission=container.GetPermissions();
permission.publiccess=BlobContainerPublicAccessType.Container;
container.SetPermissions(权限);
字符串名称=fu.FileName;
CloudBlockBlob=container.GetBlockBlobReference(名称);
blob.UploadFromStream(fu.FileContent);
int maxSize=1*1024*1024;//4 MB
如果(fu.PostedFile.ContentLength>maxSize)
{
byte[]data=fu.FileBytes;
int id=0;
int byteslength=data.Length;
int字节读取=0;
int指数=0;
列表块列表=新列表();
int numBytesPerChunk=250*1024;//每个块250KB
做
{
字节[]缓冲区=新字节[numBytesPerChunk];
int limit=index+numBytesPerChunk;
for(int循环=0;索引
无效); blocklist.Add(blockIdBase64); id++; }while(byteslength-bytesread>numBytesPerChunk)

int final=byteslength-bytesread;
字节[]finalbuffer=新字节[最终];
for(int循环=0;索引

您还可以找到Steve Marx为大文件上传开发的silverlight控件(例如)

您可以发现此链接对于研究将文件上传到块中的azure blob非常有用:

我在这里复制代码以删除外部依赖项:

 protected void btnUpload_Click(object sender, EventArgs e)
{
    CloudBlobClient blobClient;
    var storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
    blobClient = storageAccount.CreateCloudBlobClient();

    CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");
    container.CreateIfNotExist();

    var permission = container.GetPermissions();
    permission.PublicAccess = BlobContainerPublicAccessType.Container;
    container.SetPermissions(permission);

    string name = fu.FileName;
    CloudBlockBlob blob = container.GetBlockBlobReference(name);

    blob.UploadFromStream(fu.FileContent);

    int maxSize = 1 * 1024 * 1024; // 4 MB

    if (fu.PostedFile.ContentLength > maxSize)
    {
        byte[] data = fu.FileBytes; 
        int id = 0;
        int byteslength = data.Length;
        int bytesread = 0;
        int index = 0;
        List<string> blocklist = new List<string>();
        int numBytesPerChunk = 250 * 1024; //250KB per block

        do
        {
            byte[] buffer = new byte[numBytesPerChunk];
            int limit = index + numBytesPerChunk;
            for (int loops = 0; index < limit; index++)
            {
                buffer[loops] = data[index];
                loops++;
            }
            bytesread = index;
            string blockIdBase64 = Convert.ToBase64String(System.BitConverter.GetBytes(id));

            using (var ms = new MemoryStream(buffer, true))
              blob.PutBlock(blockIdBase64, ms, null);
protectedvoidbtnupload\u单击(对象发送方,事件参数e)
{
CloudBlobClient blobClient;
var storageAccount=CloudStorageAccount.FromConfigurationSetting(“DataConnectionString”);
blobClient=storageAccount.CreateCloudBlobClient();
CloudBlobContainer container=blobClient.GetContainerReference(“mycontainer”);
container.CreateIfNotExist();
var permission=container.GetPermissions();
permission.publiccess=BlobContainerPublicAccessType.Container;
container.SetPermissions(权限);
字符串名称=fu.FileName;
CloudBlockBlob=container.GetBlockBlobReference(名称);
blob.UploadFromStream(fu.FileContent);
int maxSize=1*1024*1024;//4 MB
如果(fu.PostedFile.ContentLength>maxSize)
{
byte[]data=fu.FileBytes;
int id=0;
int byteslength=data.Length;
int字节读取=0;
int指数=0;
列表块列表=新列表();
int numBytesPerChunk=250*1024;//每个块250KB
做
{
字节[]缓冲区=新字节[numBytesPerChunk];
int limit=index+numBytesPerChunk;
for(int循环=0;索引
无效); blocklist.Add(blockIdBase64); id++; }while(byteslength-bytesread>numBytesPerChunk)

int final=byteslength-bytesread;
字节[]finalbuffer=新字节[最终];
for(int循环=0;索引

您还可以找到Steve Marx为大文件上传开发的silverlight控件(例如)

嗨,Sandrino,我不知道如何传递Uri
 protected void btnUpload_Click(object sender, EventArgs e)
{
    CloudBlobClient blobClient;
    var storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
    blobClient = storageAccount.CreateCloudBlobClient();

    CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");
    container.CreateIfNotExist();

    var permission = container.GetPermissions();
    permission.PublicAccess = BlobContainerPublicAccessType.Container;
    container.SetPermissions(permission);

    string name = fu.FileName;
    CloudBlockBlob blob = container.GetBlockBlobReference(name);

    blob.UploadFromStream(fu.FileContent);

    int maxSize = 1 * 1024 * 1024; // 4 MB

    if (fu.PostedFile.ContentLength > maxSize)
    {
        byte[] data = fu.FileBytes; 
        int id = 0;
        int byteslength = data.Length;
        int bytesread = 0;
        int index = 0;
        List<string> blocklist = new List<string>();
        int numBytesPerChunk = 250 * 1024; //250KB per block

        do
        {
            byte[] buffer = new byte[numBytesPerChunk];
            int limit = index + numBytesPerChunk;
            for (int loops = 0; index < limit; index++)
            {
                buffer[loops] = data[index];
                loops++;
            }
            bytesread = index;
            string blockIdBase64 = Convert.ToBase64String(System.BitConverter.GetBytes(id));

            using (var ms = new MemoryStream(buffer, true))
              blob.PutBlock(blockIdBase64, ms, null);
        int final = byteslength - bytesread;
        byte[] finalbuffer = new byte[final];
        for (int loops = 0; index < byteslength; index++)
        {
            finalbuffer[loops] = data[index];
            loops++;
        }
        string blockId = Convert.ToBase64String(System.BitConverter.GetBytes(id));
        using (var ms = new MemoryStream(finalbuffer, true))
          blob.PutBlock(blockId, ms, null);
        blocklist.Add(blockId);

        blob.PutBlockList(blocklist); 
    }
    else
        blob.UploadFromStream(fu.FileContent);            
}