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;
  • Verified answer
    AntonioTorre Profile Picture
    574 on at
    RE: Copy blob from stream

    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á!

  • AntonioTorre Profile Picture
    574 on at
    RE: Copy blob from stream

    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?

  • AntonioTorre Profile Picture
    574 on at
    RE: Copy blob from stream

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

  • Genie Cetas Profile Picture
    472 on at
    RE: Copy blob from stream

    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.

  • Ethan-Sorenson Profile Picture
    225 on at
    RE: Copy blob from stream

    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;

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,430 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,043 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans