上传 Zip 块并在 Azure 平台上加入它们

Upload Zip Chunks and Join them on Azure Platform

我想知道.. 如果我制作一个大 Zip 文件的块并将所有块上传到容器 Blob 中的 Azure 云存储。我可以在 Azure 平台上加入这些块吗? 对于分块,我正在使用此代码,该代码还会生成 .bat 文件以重新加入分块..

public void SplitFile(){
    int numericUpDown = 100;//in MB
    string PathToCopyChunks = "";  // path to store chunks and ( .bat  ) file
    string FilePathMakeChunks = DirectoryNameToPutScannedData; //the path of file to make chunks.
    try{
        int kbs = numericUpDown * 1024;
        int chunkSize = numericUpDown * 1024 * 1024;
        byte[] buffer = new byte[4096];
        string cmdout = "copy/b ";
        FileStream infile = File.OpenRead(FilePathMakeChunks);
        for (long i = 0; i <= infile.Length / chunkSize; i++)
        {
            string fname = Path.Combine(PathToCopyChunks, Path.Combine(PathToCopyChunks, Path.GetFileName(FilePathMakeChunks)) + "." + chunkSize + "." + i.ToString().PadLeft(4, '0') + ".part");
            string fname_x = Path.GetFileName(FilePathMakeChunks) + "." + chunkSize + "." + i.ToString().PadLeft(4, '0') + ".part";
            if (i == infile.Length / chunkSize)
                cmdout += "\"" + fname_x + "\"";
            else
                cmdout += "\"" + fname_x + "\" + ";
            FileStream outfile = File.Create(fname);
            for (int kb = 0; kb <= kbs; kb++)
            {
                int len = infile.Read(buffer, 0, 1024);
                outfile.Write(buffer, 0, len); 
            }
            outfile.Close();
        }
        cmdout += " \"" + Path.GetFileName(FilePathMakeChunks) + "\"";
        string combinerbatch = Path.Combine(PathToCopyChunks, Path.Combine(PathToCopyChunks, Path.GetFileName(DirectoryNameToPutScannedData)) + "." + chunkSize + ".combine.bat");
        File.WriteAllText(combinerbatch, cmdout);
        MessageBox.Show("Splitting Done...!");
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
}

我正在将这些块连同批处理文件一起上传到 azure 存储容器中,我想 运行 我的 azure 容器中的这个批处理文件加入块。 希望这有助于理解我的问题

我正在使用此代码上传

string[] array1 = Directory.GetFiles(@"D:\Test");
string fileName = string.Empty;
foreach (string name in array1)
{
    fileName = Path.GetFileName(name);
    CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName);
    var fileStream = System.IO.File.OpenRead(name);
    blockBlob.UploadFromStream(fileStream); 
}

有两件事:

  1. 如果您希望将文件压缩到 blob 存储中,即在 blob 存储中上传大文件并期望 blob 存储将这些文件压缩到那里,那么这是不可能的。 Blob 存储是简单的文件存储。
  2. 如果你有一个大的 zip 文件,你想分块上传,然后让 blob 存储重新组合这些块来创建 zip 文件,那么这是可能的。

既然你没有提到你要使用的技术,我就用Azure REST API来描述这个过程。

您需要做的是在客户端(从您上传的位置)将文件拆分成块。每个块的大小不能超过 4MB,因为块 blob 的最大大小可以是 200GB,所以块不能超过 50,000。然后您将使用 Put Block API.

上传这些块

上传所有块后,您将指示 Blob 存储使用 Put Block List API.

创建 zip 文件