C Download Image From Url

C# Code Snippet - Download Image from URL. This.Net C# code snippet download image from URL. To use this function simply provide the URL of the image you like to download. This function read the image contents using URL and returns downloaded image as an image object. This function download image using web response stream. This tutorial will show how to download a file (image,video,zip,pdf,doc,xls,ect) from a valid URL of a particular website then save it as a physical file on server disk with ASP.NET (C#).It provides one more solution when you want to copy/move a file from a server to another server.

Active4 years, 1 month ago

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 Bish
15.2k6 gold badges38 silver badges57 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;

C Download Image From Url
Umut D.Umut D.

Not the answer you're looking for? Browse other questions tagged c#imageurlbitmapserver or ask your own question.

Active1 year, 3 months ago

I am not getting the image from url.i am not able to find Proper solution on StackOverflow. I've found two ways to convert image from URL but they are not working

And second method is

UIImage is returning nil in both conditions

i have added NStransportsecurity.

Varinder Singh iPhone Dev
Varinder Singh iPhone DevVarinder Singh iPhone Dev
2,5403 gold badges14 silver badges38 bronze badges

5 Answers

You can use

#import 'UIImageView+AFNetworking.h'

[profileImageView setImageWithURL:[NSURL URLWithString:photoURL] placeholderImage:[UIImage imageNamed:@'placeholder']];

Anjali PrasadAnjali Prasad
Samiul Islam SamiSamiul Islam Sami

This problem caused because of your ssl certificates or server side restrictions.

I have checked your image url and got following error message with SDWebImage.

Try with to solve this error message.

Error Domain=NSURLErrorDomain Code=-1200 'An SSL error has occurred and a secure connection to the server cannot be made.' UserInfo={_kCFStreamErrorCodeKey=-9806, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, NSUnderlyingError=0x1700504d0 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 '(null)' UserInfo={_kCFStreamPropertySSLClientCertificateState=0, _kCFNetworkCFStreamSSLErrorOriginalValue=-9806, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9806}}, NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSErrorFailingURLKey=https://mastersoftwaretechnologies.com:8014/uploads/50x50/6455.png, NSErrorFailingURLStringKey=https://mastersoftwaretechnologies.com:8014/uploads/50x50/6455.png, _kCFStreamErrorDomainKey=3}

Note - You need to set ATS as per your ssl certificate.

Download Image Car

OR

Run this command in terminal for more explanation.

KKRocksKKRocks
7,2961 gold badge11 silver badges72 bronze badges

Please check the link which you have provided have some restriction and its connection is closed for some reason.

If the link is correct or there is no restriction you can able to see the image content in browser while ping the link into it.

For liable image download, if you want to do native method you can go for:

Native image downloader:

You will be getting download progress and complete delegate call back.

SDWebImage:

Download Image From Url Ios Objective C

Abilash BalasubramanianAbilash Balasubramanian

Better to use SDWebImage library for downloading the image, its managing lots of work at backend including memory management and cache.

Install using pod 'SDWebImage-ProgressView'

Use following methods with this url https://test.com:/image.png

Koen
2,4003 gold badges25 silver badges61 bronze badges
Raza.najamRaza.najam

Not the answer you're looking for? Browse other questions tagged iosobjective-cuiimageview or ask your own question.