0

我尝试将大文件拆分为 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();
}
4

0 回答 0