我试图将大文件分成4KB的小块,并将每个块发送到oracle云,但是请求正在中止。请检查拆分代码是否正确,或者我做错了其他事情。
FileStream rdr = new FileStream(fileToUpload, FileMode.Open, FileAccess.Read);
byte[] inData = new byte[4096];
long chunkSize= rdr.Length;
long chunkBytesToRead = chunkSize;
using (Stream reqStream = request.GetRequestStream())
{
while (rdr.Position < rdr.Length)
{
int chunkBytesRead = 0;
int maxread = 4096;
while (chunkBytesRead < chunkSize)
{
int bytesRead = rdr.Read(inData,0,maxread);
if (bytesRead == 0)
{
break;
}
reqStream.Write(inData, 0, bytesRead);
chunkBytesToRead -= bytesRead;
if (chunkBytesToRead < 4096)
maxread = (int)chunkBytesToRead;
chunkBytesRead += bytesRead;
}
}
reqStream.Close();
}