Hello .net team!
I have small app on .net core 3.1, part of it downloads images from web and stores in DB. It works nice on windows. On linux (debian 10) it works fine with some images and throws images on other. I tested this code on windows to donwload thousands of images, so there is something wrong with linux one.
here is code to get images:
var retWOrks = CrawlerBitmap.DownloadImage(
"http://avatars.mds.yandex.net/get-autoru-vos/2106286/3fbfed61bff31136bcda59010e092218/1200x900n");
var ret =CrawlerBitmap.DownloadImage(
"http://auto.ru/_crpd/26BRt9D25/f3cdbc3cR/DBGiNNzAMe1C9L3wp-XU-dmc05ME9LCtU9FZci7PTFEJgDKpjvDebkFTQ38vrMoRDm7KPdrwAzdq2iWUU55CKQRc8wTMgHWcFu2o2Zqs0ayEvKvKdeTMiEcQPf6yB1QxSJjG2ccZm59ouoZyWlhb2Muaj3S3OJO_Jpf0UV5amnncWUYsTEi4ASJgbPAHiUhV1Snnb6R1IK2jzP1OmqvUlZQAyokDfbsD8BZKUqZ4hwArKhekj4CHD1oPUJGyykaxyB2E");
Console.WriteLine($@"{ret.Height}");
Console.WriteLine($@"{retWOrks.Height}");
Console.WriteLine("Hello world");
and here is code for DownloadImage:
public static class CrawlerBitmap
{
private static System.Net.WebClient _webClient;
public static Image DownloadImage(string fromUrl)
{
if (_webClient == null)
{
_webClient = new System.Net.WebClient();
}
Image ret = null;
Random rand1 = new Random();
Console.WriteLine($"Started at {DateTime.Now}");
using (var stream = _webClient.OpenRead(fromUrl))
{
ret = Image.FromStream(stream);
}
Console.WriteLine($"Exiting at {DateTime.Now}");
Thread.Sleep(TimeSpan.FromSeconds(rand1.Next(5, 15)));
return ret;
}
}
Output:
fjod@fjordbox:~/crawler/publish$ /usr/bin/dotnet /home/fjod/crawler/publish/CuteDOS.dll
Started at 1/19/2020 4:08:08 AM
Exiting at 1/19/2020 4:08:08 AM
Started at 1/19/2020 4:08:17 AM
Unhandled exception. System.ArgumentException: Parameter is not valid.
at System.Drawing.SafeNativeMethods.Gdip.CheckStatus(Int32 status)
at System.Drawing.Image.InitializeFromStream(Stream stream)
at System.Drawing.Image.LoadFromStream(Stream stream, Boolean keepAlive)
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement)
at System.Drawing.Image.FromStream(Stream stream)
at Domain.ImageComparison.CrawlerBitmap.DownloadImage(String fromUrl) in /builds/fjod/crawler/Domain/ImageComparison/CrawlerBitmap.cs:line 25
line 25 is
ret = Image.FromStream(stream);
Hello .net team!
I have small app on .net core 3.1, part of it downloads images from web and stores in DB. It works nice on windows. On linux (debian 10) it works fine with some images and throws images on other. I tested this code on windows to donwload thousands of images, so there is something wrong with linux one.
here is code to get images:
and here is code for DownloadImage:
Output:
line 25 is
ret = Image.FromStream(stream);