Item Picture- Webservice

 

Hey Friends,

I was just working on an assignment where I got the need of the customer like they want the Item Picture via web service. Another validation they put in was they don’t want the item picture to be saved on any particular directory instead they want on fly.

So now in standard NAV 2018 Item picture data-set has been changed from Blob to Mediaset so it was then added challenge. We need to convert the picture into streams and bytes and then we can send this over service but how to convert it into bytes. Converting Blob we all are well experienced but what about Mediaset.

There’s a new virtual table which Microsoft has introduced to maintain this identity in Blob which is Tenant Media. The reason why Microsoft did so is now we have the capability to add multiple pictures for an item.

So here is the piece of code how we are suppose to do this.

//RWN
Item.GET(ItemNo);
IF Item.Picture.COUNT = 0 THEN
EXIT(”);

TenantMedia.GET(Item.Picture.ITEM(1));
TenantMedia.CALCFIELDS(Content);
IF TenantMedia.Content.HASVALUE THEN BEGIN
CLEAR(PictureText);
CLEAR(PictureInStream);
TenantMedia.Content.CREATEINSTREAM(PictureInStream);
TempBlob.DELETEALL;
TempBlob.INIT;
TempBlob.Blob.CREATEOUTSTREAM(PicOutStream);
COPYSTREAM(PicOutStream,PictureInStream);
TempBlob.INSERT;
TempBlob.CALCFIELDS(Blob);
PictureText.ADDTEXT(TempBlob.ToBase64String);
END;
//RWN

Return this Picturetext in Web-service and they have to convert it from Base 64 string, they will have the real image.

Item Record Item
TenantMedia Record Tenant Media
PictureText BigText
PictureInStream InStream
TempBlob Record TempBlob

CHEERS

File to Byte Conversion – Client to Server Move

Hey Friends,

This is a very simple post on how to move a file from your client computer to server computer. We all are well equipped and experienced in moving a file directly from a physical path, if we simply need to just copy that file as we all have expertise in using File Management Codeunit.  I just experienced a case where client was scanning the file from NAV and then and there he requested that the scanned file can anyhow directly move into server computer without any physical storage in the current client machine.

As the scanning form was a part of .NET dll so to achieve this and after scanning I sent that scanned file as a parameter in Big-text format to NAV Web Service. Here the actual work comes into play. Look at the below piece of code

//RWN
Byte:=Convert.FromBase64String(FileInBigText); FileInBigText includes scanned file
MemoryStream:=MemoryStream.MemoryStream(Byte);
TempBlob.DELETEALL;
TempBlob.INIT;
TempBlob.Blob.CREATEOUTSTREAM(OutStream);
MemoryStream.WriteTo(OutStream);
TempBlob.INSERT;

File.CREATE(FilePath); Filepath Includes Path + Name + FileType
File.CREATEOUTSTREAM(FileOutStream);
TempBlob.Blob.CREATEINSTREAM(FileInStream);
COPYSTREAM(FileOutStrm,FileInStream);
File.CLOSE;
//RWN

CHEERS