web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Copy blob from stream

(0) ShareShare
ReportReport
Posted on by 574

I have a blob field (subtype bmp). I know this is going to be deprecated by media field type, but I still need it for display a picture in a repeater without using a brick view.

My question is how do I write this blob field with a stream. I mean, in a secondary table I have this blob field and when I link this table with an item no. I want to copy the picture of that item into this blob field.  This is my code (inspired in a blog from Stefano Demiliani) but I must be doing something wrong, since picture does not show up.

local procedure loadMainPicture(sku: Code[20])
    var
        item: Record Item;
        media: Record "Tenant Media";
        instr: InStream;
        outstr: OutStream;
        temblob: Codeunit "Temp Blob";
  
    begin
        item.get(sku);
        if item.Picture.Count = 0 then exit;
        media.get(item.Picture.Item(1));
        media.Content.CreateInStream(instr);
        temblob.CreateInStream(instr);
        temblob.CreateOutStream(outstr);
        "Main Picture".CreateOutStream(outstr);
        Modify;
    end;
I have the same question (0)
  • Ethan-Sorenson Profile Picture
    225 on at

    Astur,

    It looks like you are really close, you just need to use CalcFields to actually retrieve the content.

    I didn't test this, but it should look something like this.

    local procedure loadMainPicture(sku: Code[20])

       var
           item: Record Item;
           media: Record "Tenant Media";
           instr: InStream;
           outstr: OutStream;
           temblob: Codeunit "Temp Blob";
           index: Integer;
       begin
           if item.Picture.Count = 0 then exit;
           for index := 1 to Picture.COUNT do begin
               if media.Get(Picture.Item(index)) then begin
                   media.CalcFields(Content);
                   if media.Content.HasValue() then begin
                       media.Content.CreateInStream(instr);
                       temblob.CreateInStream(instr);
                       temblob.CreateOutStream(outstr);
                       "Main Picture".CreateOutStream(outstr);
                       Modify;
                   end;
               end;
           end;
  • Genie Cetas Profile Picture
    472 on at

    Hi Asture,

    Normally to read the blob field we have to use the CALCFIELD method and we can use COPYSTREAM method for copy blob from stream. Here I have made some changes in your snippet please refer that.

    local procedure loadMainPicture(sku: Code[20])

       var

           item: Record Item;

           media: Record "Tenant Media";

           instr: InStream;

           outstr: OutStream;

           temblob: Codeunit "Temp Blob";

       begin

           item.get(sku);

           if item.Picture.Count = 0 then exit;

           media.get(item.Picture.Item(1));

    media.CalcFields(Content);

           if media.Content.HasValue() then begin

              media.Content.CreateInStream(instr);

              "Main Picture".CreateOutStream(outstr);

      COPYSTREAM(outstr,instr);

              Modify;

          End

    End

    I hope the information helps you identify the source of the issue.

  • AntonioTorre Profile Picture
    574 on at

    I have tried that code and still dont work. Maybe I am missing something.

  • AntonioTorre Profile Picture
    574 on at

    This is not working since outstr is not initialize. Even I have initialized it, still does not work. Maybe I am doing something wrong, but, have you checked your code? and is it working fine?

  • Verified answer
    AntonioTorre Profile Picture
    574 on at

    I finally got the solution. Sometimes we love to make things harder that what they really are.

    If you need to copy one blob to another blob, just do the following:

    destinationtable.blobfield := sourcetable.blobfield;

    et voilá!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,135

#2
YUN ZHU Profile Picture

YUN ZHU 733 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 612

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans