Please, can anybody tell me how to figure this out? I have an image URL (for example: http://domain.com/picture.png) and I want to download it to BLOB type variable.
You can use below code for download the image from web and save it local. After that you need to read downloaded file and save it into BLOB.
usage
fnDownloadImage('http://static.adzerk.net/Advertisers/5fa811fa1a3e40f1a3435478bd1364a0.png','C:\Dummy\p.png',1);
function name : fnDownloadImage
Var Name DataType Subtype Length
No ptxtUrl Text 1024
No ptxtSaveAsFileName Text 1024
No poptSaveAsOption Option
Name DataType Subtype Length
atXMLHTTP30 Automation 'Microsoft XML, v3.0'.XMLHTTP30
atAdodbStream Automation 'Microsoft ActiveX Data Objects 6.1 Library'.Stream
IF STRLEN(ptxtUrl) = 0 THEN
EXIT(FALSE);
CREATE(atXMLHTTP30,FALSE,TRUE);
atXMLHTTP30.open('GET', ptxtUrl,FALSE);
atXMLHTTP30.setRequestHeader('Content-type','image/png');
atXMLHTTP30.send;
CASE atXMLHTTP30.status OF
200: BEGIN
CREATE(atAdodbStream,FALSE,TRUE);
atAdodbStream.Type := 1; // adTypeBinary
atAdodbStream.Open;
atAdodbStream.Write(atXMLHTTP30.responseBody);
atAdodbStream.SaveToFile(ptxtSaveAsFileName,poptSaveAsOption + 1); // adSaveCreateNotExist = 1, adSaveCreateOverWrite = 2
atAdodbStream.Close;
END;
ELSE
MESSAGE('%1',atXMLHTTP30.statusText);
END;
IF NOT ISCLEAR(atAdodbStream) THEN
CLEAR(atAdodbStream);
IF NOT ISCLEAR(atXMLHTTP30) THEN
CLEAR(atXMLHTTP30);
EXIT(TRUE);
Answers
Use DotNet "System.Net.WebClient" to open the file from your URL and save it into Stream. And then save to your BLOB.
Oh no! It not work for CC
Regards,
You can use below code for download the image from web and save it local. After that you need to read downloaded file and save it into BLOB.
Regards,