1
I have a file list, and I need to know if it was uploaded to a storage facility. The idea to facilitate the process is to concatenate the file name, generate a URL and try to download the file, if it returns 404 my method returns false
.
public static bool ThumbExist(string contributorID,string imageID)
{
string url = String.Format("https://servico.com/file/{0}/{1}.jpg", contributorID, imageID);
byte[] myDataBuffer;
WebClient myWebClient = new WebClient();
myWebClient.Headers.Add("User-Agent: Other");
try
{
myDataBuffer = myWebClient.DownloadData(url);
return true;
}
catch (Exception e) //Quando não existe o servidor retorna um 404 e cai aqui
{
return false;
}
}
How can I verify ONLY if the server returns me at least 1 byte
without having to download the whole image.
I need this because if the image exists, my code downloads it completely and it takes unnecessary time.