Skip to main content
Hello All.

Please I want to display company image from attachment object that contains Body and was told that this body contains array of bytes ,but how to connect to this url and parse the result

I have already attached Attachment object but how to convert the body to image using the base64 and the body is url like that (/Attachment/id/Body)

Thanks in advance
1 Antwort
  1. 9. Juli 2015, 11:16
    Hi Abanoub,

    First query the custom object and get the image url. Now, do an HTTP GET to retrieve the image and then assign it to FeedItem insertion.

    To get the blob data from an image url

    Http h = new Http();

    HttpRequest req = new HttpRequest();

    string firstImageURL = 'http://www.samplesite.com/testimage.jpg';

    firstImageURL = firstImageURL.replace(' ', '%20');

    req.setEndpoint(firstImageURL);

    req.setMethod('GET');

    req.setHeader('Content-Type', 'image/jpeg');

    req.setCompressed(true);

    req.setTimeout(60000);

                    

    HttpResponse res = null;

    res = h.send(req);

    string responseValue = '';

    responseValue = res.getBody();

    system.debug('Response Body for File: ' + responseValue);

    blob image = res.getBodyAsBlob();

    // Prepare the FeedItem with the image blob for insertion

    FeedItem post = new FeedItem();

    post.ParentId = u.id;

    post.CreatedById='005E0000003XWRs';

    post.Body ='Hello '+u.name;

    post.ContentData = image;

    post.ContentFileName = 'sample.png';

    insert post;

    Please let me know if this helps

    Best Regards

    Naga kiran
0/9000