i am using Wininet
to download images and save them to memory stream but for more management reason i want to allow only gif images
and jpg
to be downloaded i tried to add check for FURL but extract file extension from url
is bad step for me here is my wininet
function
function DownloadToStream: Boolean;
var
hSession : HINTERNET;
hService : HINTERNET;
lpBuffer : array[0..1023] of Byte;
dwBytesRead : DWORD;
dwBytesAvail : DWORD;
dwTimeOut : DWORD;
Sessionname : String;
Setsession : Pwidechar;
begin
Result := False;
Sessionname := nameofsession;
Setsession := pwidechar(Sessionname);
hSession := InternetOpen(Setsession, INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if not Assigned(hSession) then Exit;
try
hService := InternetOpenUrl(hSession, PChar(FUrl), nil, 0, 0, 0);
if hService = nil then
Exit;
try
dwTimeOut := 60000;
InternetSetOption(hService, INTERNET_OPTION_RECEIVE_TIMEOUT, @dwTimeOut, SizeOf(dwTimeOut));
if InternetQueryDataAvailable(hService, dwBytesAvail, 0, 0) then
repeat
if not InternetReadFile(hService, @lpBuffer[0], SizeOf(lpBuffer), dwBytesRead) then
Break;
if dwBytesRead <> 0 then
FMs.WriteBuffer(lpBuffer[0], dwBytesRead);
until dwBytesRead = 0;
Result := FMS.Size > 0;
finally
InternetCloseHandle(hService);
end;
finally
InternetCloseHandle(hSession);
end;
end;