Active4 years, 1 month ago
How to Get the URL for Pictures. This wikiHow teaches you how to find the Internet address for an online picture. The easiest and most-common way to do this is by using a Google search, though you can find the URL for pictures in most.
I use a website to get stats on wifi usage. The website creates an image of a graph representation of the data. The way it does this is by the user, setting a date. So for example, lets say it was last months statistics. The website generates a URL which is then sent to the server and the server returns an image. an examples of the link is like this:
The problem is, I am making a third party program that will download this image to be used in my program. However, I cannot use the file. It is as if the file is corrupt or something. I have tried a few methods but maybe someone can suggest a different approach. Basically, how do I download an image that is generated by a server from a URL link?
P.S.
Just noticed that if I download the file by right clicking through a browser and save, the image downloads with a size of 17.something kilobytes. But if I use the WebClient method to download the image, it only downloads 1.5kb. Why would that be? Seems like the WebClient method does not download completely.
Currently my code
TempFolderPath is my desktopTempFolder
UPDATEOut of random, I decided to see the raw data of the file with notepad and interestingly, the image data was actually a copy of the websites homepage html code, not the raw data of the image :S how does that make sense?
Makar Emelyanov
Makar EmelyanovMakar Emelyanov
2 Answers
Dave BishDave Bish15.2k66 gold badges3838 silver badges5757 bronze badges
First of all, you have to understand link texture. If all links are same or close to each other, you have to use substring/remove/datetime etc. methods to make your new request link. For example;
Umut D.Umut D.
Not the answer you're looking for? Browse other questions tagged c#imageurlbitmapserver or ask your own question.
Active7 months ago
I am trying to download images from the site. The code which I am using is working fine while the image is available. If the image it not available it is creating a problem. How to validate availability of the image?
Code:
Method 1:
Method 2:
Upload Image
Edit:
Stream has the following statements:
MicroVirus4,74222 gold badges2020 silver badges4545 bronze badges
GeethGeeth2,8461919 gold badges6868 silver badges125125 bronze badges
5 Answers
There is no need to involve any image classes, you can simply call
WebClient.DownloadFile
:Update
Since you will want to check whether the file exists and download the file if it does, it's better to do this within the same request. So here is a method that will do that:
Since you will want to check whether the file exists and download the file if it does, it's better to do this within the same request. So here is a method that will do that:
In brief, it makes a request for the file, verifies that the response code is one of
Fredrik MörkFredrik MörkOK
, Moved
or Redirect
and also that the ContentType
is an image. If those conditions are true, the file is downloaded.136k2323 gold badges256256 silver badges319319 bronze badges
I have used Fredrik's code above in a project with some slight modifications, thought I'd share:
Rear license plate mounting bracket. Main changes are:
- using a try/catch for the GetResponse() as I was running into an exception when the remote file returned 404
- returning a boolean
germankiwigermankiwi
Alexander NikolaevAlexander Nikolaev
CodeNinjaCodeNinja
The best practice to download an image from Server or from Website and store it locally.
Mohamad-Al-IbrahimMohamad-Al-Ibrahim