我想知道如果我製作一個大Zip文件的塊並將所有塊上載到Container Blob中的Azure雲存儲上。我可以在Azure平臺上加入這些塊嗎? 爲分塊我使用這個代碼也產生.bat文件用於重新加入塊..上傳Zip塊並在Azure平臺上加入它們
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存儲容器批處理文件上傳沿着這些塊,我想在運行這個批處理文件我的天藍色容器加入大塊。 希望這將有助於理解我的問題
,我使用這個代碼上傳
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);
}
你能否更詳細地描述你需要分開塊,上傳到不同的斑點,下載,然後重新加入的原因?這是一個性能問題還是其他特定於應用程序的原因? –
@Emily因爲我的文件大約是10 GB,這就是爲什麼我要分塊。在大塊上傳很容易與低互聯網速度。或者如果我將來需要並行上傳,那麼它會幫助完整。 –
如果使用客戶端庫UploadFromStream方法(就像我看到的那樣),如果將並行度因子設置爲> 1,則會爲您並行上傳並行上傳。有沒有理由不適合你? –