Export Blob to File, what extension?

ta5
Member Posts: 1,164
Hi
I want to export the files stored in myTable.myBlob to separate files, from a batch.
The problem is the extension. How can I give the correct file extension to the created files? It could be bmp, jpg etc., so I don't know.
Thx in advance
Thomas
I want to export the files stored in myTable.myBlob to separate files, from a batch.
The problem is the extension. How can I give the correct file extension to the created files? It could be bmp, jpg etc., so I don't know.
Thx in advance
Thomas
0
Answers
-
Hi Thomas
Most files got magic numbers - a few bytes in the beginning identifying the type of the contents.
See https://en.wikipedia.org/wiki/Magic_number_(programming)0 -
Store the extension in a separate field when you populate the BLOB.Brian Rocatis
Senior NAV Developer
Elbek & Vejrup0 -
Hi experts
Thx for your answers. Because there are already data existing, I'll opt for the "Magic Numbers"!
Regards
Thomas0 -
I have some working code which does this. I'll post it here if I can still find it.0
-
What about this? This code can probably be improved in many ways, but it does the job for images and should get you going.
PROCEDURE GetFileType@1000000005(BlobRef@1000000000 : Record 99008535) : Text[3];
VAR
NVInStream@1000000005 : InStream;
MyChar@1000000004 : Char;
MyString@1000000003 : Text[10];
i@1000000002 : Integer;
Extention@1000000001 : Text[3];
BEGIN
//**
// Function to resolve file extension from the blob contents..
//*
BlobRef.Blob.CREATEINSTREAM(NVInStream);
FOR i := 1 TO 10 DO BEGIN
NVInStream.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');
EXIT(Extention);
END;0 -
Hi Marijn
Thx for the code. I'll give it a try!
Regards
Thomas0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions