Writing a BLOB to a file

bhalpinbhalpin Member Posts: 309
Hi.

I've tried, but can't find documentation to explain this simply (well, simple enough for me) or an example.

All I want to do is write the contents of a BLOB (a picture) to a file - without the "Save As" dialog (I have a filename/path already.)

This is as far as I get:
// PicFile  - File
// OStream - Outstream
// Filename - text(30)

FileName := 'C:\SOMEFILENAME.BMP';
IF EXISTS(FileName) THEN
  ERASE(FileName);
PicFile.CREATE(FileName);
PicFile.TEXTMODE(FALSE);
PicFile.CREATEOUTSTREAM(OStream);
OStream.WRITE(Rec.Blob);
PicFile.CLOSE;

And this is the error:

You are using an invalid datatype for this function

Can someone show me where I'm missing something?

Thanks!!!

(PS - This is NAV 4.0 SP3.)

Answers

  • MBergerMBerger Member Posts: 413
    Have a look at the helpfile, for the EXPORT() function of the BLOB datatype.
    EXPORT (BLOB)
    Use this function to export a BLOB (Binary Large Object).
    
  • bhalpinbhalpin Member Posts: 309
    Ah, right, got it: BLOB.EXPORT(<filename>,FALSE);

    Thanks.
  • livingdolllivingdoll Member Posts: 45
    This function has become obsolete in the RTC :-(
    Is there a way to export the content of a blob (xml in my case) to a file from the RTC?

    Regards,
    Jes
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    in Codeunit 419 - 3-Tier Automation Mgt., we have two functions for importing and exporting BLOB files..BLOBImport and BLOBExport for RTC

    Have a look at them.. :thumbsup:
  • livingdolllivingdoll Member Posts: 45
    very cool! Thanx, Mohana!
  • RakshithaRakshitha Member Posts: 13
    I am importing all files (*.*) in Blob Import Function but while exporting i need to give the extension. Please let me know how to give extension of the file while is present in the Blob field
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    As the filename (and extension) is not stored in the BLOB-field, you need to store it in a separate field in your table when importing the BLOB.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • RakshithaRakshitha Member Posts: 13
    Can you please explain me in detail how to store it in a sepearate field in Table

    This is my code in Import :

    FileExists := Rec.Attachment.HASVALUE;
    IF Rec.Attachment.IMPORT('*.*',TRUE) = '' THEN
    EXIT
    ELSE
    IF STRPOS(Rec.Attachment.IMPORT('*.*',TRUE),'.') = 0 THEN
    ExtensionFile := COPYSTR(Rec.Attachment.IMPORT('*.*',TRUE),1);
    MODIFY;
    IF FileExists THEN
    IF NOT CONFIRM(Text004,FALSE) THEN
    EXIT;
    CurrForm.SAVERECORD;
  • RakshithaRakshitha Member Posts: 13
    Can anybody tell me how to store filename and its extension which is imported through Blob Import Function (*.*)?
Sign In or Register to comment.