Options

Resolve file extension from contents BLOB field

MarijnMarijn Member Posts: 69
edited 2013-08-27 in NAV Three Tier
Hello,

I want to move the contents of a BLOB field from table A to table B in NAV2013. These are images of different types, like .bmp and .jpg. (NAV2013 can show more file types besides .bmp, so the users did upload all kinds). There is no column in the table with a file name or extension. Is there a way to work the name or at least the file extension out?

When the right mouse button is clicked on a BLOB field with subtype Bitmap, the control element offers the user the option to save the picture. Apparently, this control elements defaults the file extension. So somehow it can be done, but how? Thanks for any tips.

Comments

  • Options
    MBergerMBerger Member Posts: 413
    Export your file, open it in binary mode and examine the first few bytes of your file to get the format :

    BMP : First 2 bytes of the file are BM ( 42 4D )
    JPG : Bytes 7..10 of the file are JFIF ( 4A 46 49 46 )
    GIF : first 3 bytes f the file are GIF ( 47 49 46 )
    PNG : Bytes 2..4 of the file are PNG ( 50 4E 47 )
  • Options
    MarijnMarijn Member Posts: 69
    Thank you very much. This is my first attempt and it seems to work fine.

    MyTable.Picture.CREATEINSTREAM(MyInStream);

    FOR i := 1 TO 10 DO BEGIN
    MyInStream.READ(MyChar, 1);
    MyString += FORMAT(MyChar);
    END;

    IF COPYSTR(MyString, 7, 4) = 'JFIF' THEN
    Extention := 'jpg'
    ELSE IF COPYSTR(MyString, 2, 3) = 'PNG' THEN
    Extention := 'png'
    ELSE IF COPYSTR(MyString, 1, 3) = 'GIF' THEN
    Extention := 'gif'
    ELSE IF COPYSTR(MyString, 1, 2) = 'BM' THEN
    Extention := 'bmp'
    ELSE
    ERROR('unresolved');
Sign In or Register to comment.