bezzad / Downloader

Fast, cross-platform and reliable multipart downloader with asynchronous progress events for .NET applications.
MIT License
1.25k stars 193 forks source link

Error when server not support download in range #119

Closed kyuranger closed 5 months ago

kyuranger commented 1 year ago

I am a beginner and I want to create a sample project to test.

Here is the URL(but the server not support range download): https://cdn.pixabay.com/vimeo/576083058/Hello%20-%2081605.mp4?width=1920&hash=e6f56273dcd2f28fd1a9fe6e77f66d7e157b33f6&download=1

And here is my code:

DownloadService Downloader;
var downloadOpt = new DownloadConfiguration()
{
    // usually, hosts support max to 8000 bytes, default values is 8000
    BufferBlockSize = 8000,
    // file parts to download, default value is 1
    ChunkCount = 1,
    // download speed limited to 2MB/s, default values is zero or unlimited
    MaximumBytesPerSecond = 5,
    // the maximum number of times to fail
    MaxTryAgainOnFailover = 5,
    // download parts of file as parallel or not. Default value is false
    ParallelDownload = false,
    // number of parallel downloads. The default value is the same as the chunk count
    ParallelCount = 1,
    // timeout (millisecond) per stream block reader, default values is 1000
    Timeout = 1000,
    // set true if you want to download just a specific range of bytes of a large file
    RangeDownload = false,
    // floor offset of download range of a large file
    RangeLow = 0,
    // ceiling offset of download range of a large file
    RangeHigh = 0,
    // clear package chunks data when download completed with failure, default value is false
    ClearPackageOnCompletionWithFailure = true,
    CheckDiskSizeBeforeDownload = true,
    ReserveStorageSpaceBeforeStartingDownload = true,                
};
Downloader = new DownloadService(downloadOpt);
Downloader.Package.IsSupportDownloadInRange = false;
Downloader.DownloadFileCompleted += DownloadCompleted;
Downloader.DownloadProgressChanged += DownloadProgressChanged;
Downloader.ChunkDownloadProgressChanged += ChunkDownloadProgressChanged;
Downloader.DownloadStarted += DownloadStarted;
DirectoryInfo DI = new DirectoryInfo(@"C:\downloads\");
Downloader.DownloadFileTaskAsync("https://cdn.pixabay.com/vimeo/576083058/Hello%20-%2081605.mp4?width=1920&hash=e6f56273dcd2f28fd1a9fe6e77f66d7e157b33f6&download=1", DI);

However, even I set the RangeDownload to false, ChunkCount to 1, ParallelDownload to false, ParallelCount to 1 and Package.IsSupportDownloadInRange to false. The DownloadCompleted event still report the error "The downloader cannot continue downloading because the network or server failed to download in range." and can not download the file.

What's wrong with my code? Thank you.

bezzad commented 1 year ago

The value of the MaximumBytesPerSecond is so low and not reachable speed to the server. Please set it to zero and test it again.

kyuranger commented 1 year ago

The value of the MaximumBytesPerSecond is so low and not reachable speed to the server. Please set it to zero and test it again.

All right, I just want to test download and I cannot find a file large enough, so I have to do it like this.

bezzad commented 1 year ago

To test the download you can use your own file API like the Downloader.DummyHttpServer project. Which can provide any size of file to download. For a usage sample, please see the Downloader.Sample project which executes the API server before downloading and creates the download links in DownloadList.json.

Also, you can use the below web server to provide large-size files: File Example

kyuranger commented 1 year ago

To test the download you can use your own file API like the Downloader.DummyHttpServer project. Which can provide any size of file to download. For a usage sample, please see the Downloader.Sample project which executes the API server before downloading and creates the download links in DownloadList.json.

Also, you can user the below web server to provide large size files: File Example

Thank you so much. I consider it should post the https://file-examples.com/ in the project home page. This would help so many people to test their sample project.

kyuranger commented 1 year ago

I am afraid for reopening this issue again. I have been busy and haven't developed for a long time. Now I tried to modify the MaximumBytesPerSecond from 1 to 1024 1024 2. However, the error "The downloader cannot continue downloading because the network or server failed to download in range." still throws in DownloadFileCompleted event and cannot download the file successfully.

bezzad commented 1 year ago

@kyuranger Take it easy and make sure you can open it again whenever you have a problem. I will check it and answer here. it takes a few days because now I'm busy.

kyuranger commented 1 year ago

Thank you very much for your hard work

sgf commented 11 months ago
{"ClassName":"System.Net.WebException" "Message":"The operation has timed out." "Data":null "InnerException":null "HelpURL":null "StackTraceString":"   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.Net.WebRequest.<>c.<GetResponseAsync>b__68_2(IAsyncResult iar)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar  Func`2 endFunction  Action`1 endAction  Task`1 promise  Boolean requiresSynchronization)
--- End of stack trace from previous location ---
   at Downloader.Request.FetchResponseHeaders(Boolean addRange) in D:\Programming\Personal\Downloader\src\Downloader\Request.cs:line 101
   at Downloader.Request.IsSupportDownloadInRange() in D:\Programming\Personal\Downloader\src\Downloader\Request.cs:line 181
   at Downloader.Request.GetFileSize() in D:\Programming\Personal\Downloader\src\Downloader\Request.cs:line 162
   at Downloader.DownloadService.StartDownload() in D:\Programming\Personal\Downloader\src\Downloader\DownloadService.cs:line 186" "RemoteStackTraceString":null "RemoteStackIndex":0 "ExceptionMethod":null "HResult":-2146233079 "Source":"System.Net.Requests" "WatsonBuckets":null}

does this error is the same issues ?

im not sure.but its throw on windows 7, but not on windows 10 by .net 6.0

bezzad commented 11 months ago

@sgf we can't realize the main of your issue with this data. Please give more info and the URL and configs.

sgf commented 11 months ago

@sgf we can't realize the main of your issue with this data. Please give more info and the URL and configs.

This problem occurs on a customer's machine, and I will continue to keep an eye on it. If the same thing happens next time, I will report it here to add more details. If it doesn't happen again, please ignore my submission.