アイデアは単純です。ユーザーが別のWebサイトでホストされているファイルの直接リンクを配置できるサービスを作成しています。プログラムは、そのリモートサーバーへのストリームを開き、ファイルの読み取りをバイト単位で開始して、読み取った各ファイルを返します。ユーザーへのバイト。
例:インターネットダウンロードマネージャーが私のページに移動し、コードがリモートファイルをフェッチしてバイト単位で読み取り、各バイトをインターネットダウンロードマネージャーに返してファイルをダウンロードします。
これが私のコードです
public void Index()
{
using (WebClient wcDownload = new WebClient())
{
try
{
// Create a request to the file we are downloading
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://FILE-IS-NOT-ON-MY-SERVER.com/file.zip");
// Set default authentication for retrieving the file
webRequest.Credentials = CredentialCache.DefaultCredentials;
// Retrieve the response from the server
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
// Ask the server for the file size and store it
Int64 fileSize = webResponse.ContentLength;
// Open the URL for download
Stream strResponse = wcDownload.OpenRead("http://FILE-IS-NOT-ON-MY-SERVER.com/file.zip");
// It will store the current number of bytes we retrieved from the server
int bytesSize = 0;
// A buffer for storing and writing the data retrieved from the server
byte[] downBuffer = new byte[500000000];
// Loop through the buffer until the buffer is empty
while ((bytesSize = strResponse.Read(downBuffer, 0, downBuffer.Length)) > 0)
{
// i want to return each byte to the user for example Internet Download Manager
}
// When the above code has ended, close the streams
strResponse.Close();
}
catch (Exception)
{
}
}
}
私はそれが厄介であることを知っていますが、私は本当に各バイトをユーザーに返す方法を知りません。