+ Start a Discussion

store external image as an attachment

Hi Guys,


I've a url of external image and I want to download it and store it to attachment via apex code itself. Below code I am writing


   Http h = new Http();
    HttpRequest req = new HttpRequest();
       HttpResponse res = h.send(req);

		Attachment attach = new Attachment();
               Blob b=Blob.valueof(res.getBody());

		attach.Body = b;
		attach.Name = String.valueOf('FirstPageImage4.png');
		attach.ContentType = 'image/png';
		attach.ParentId ='a00E0000001Ayk0'; 
		insert attach;

 I've also added URL to remote host. But when run it. Attachment stores well but when i view it screen comes blank. I saw the body field it show something like '7+777+77.....'


But when samething i do manually (Downloaded image to desktop and then uploaded it to attachment on particular record)

It works fine.


What I am missing?