Discussions
Activity
Best Of...
Sign In
·
Register
Home
›
NAV Three Tier
Howdy, Stranger!
It looks like you're new here. Sign in or register to get started.
Sign In
Register
Quick Links
Categories
Recent Discussions
Activity
Best Of...
Unanswered
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
115
Navision DOS
854
Navision e-Commerce
1K
NAV Tips & Tricks
772
NAV Dutch speaking only
615
NAV Courses, Exams & Certification
2K
Microsoft Dynamics-Other
1.5K
Dynamics AX
304
Dynamics CRM
109
Dynamics GP
10
Dynamics SL
1.5K
Other
993
SQL General
384
SQL Performance
34
SQL Tips & Tricks
34
Design Patterns (General & Best Practices)
Architectural Patterns
10
Design Patterns
5
Implementation Patterns
53
3rd Party Products, Services & Events
1.7K
General
1.1K
General Chat
1.6K
Website
79
Testing
1.2K
Download section
23
How Tos section
260
Feedback
12
NAV TechDays 2013 Sessions
13
NAV TechDays 2012 Sessions
Export Blob to File, what extension?
ta5
Member
Posts:
1,164
2015-09-23
edited 2015-09-28
in
NAV Three Tier
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
0
Answers
lynge
Member
Posts:
85
2015-09-24
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
rocatis
Member
Posts:
163
2015-09-24
Store the extension in a separate field when you populate the BLOB.
Brian Rocatis
Senior NAV Developer
Elbek & Vejrup
0
ta5
Member
Posts:
1,164
2015-09-24
Hi experts
Thx for your answers. Because there are already data existing, I'll opt for the "Magic Numbers"!
Regards
Thomas
0
Marijn
Member
Posts:
69
2015-09-24
I have some working code which does this. I'll post it here if I can still find it.
0
Marijn
Member
Posts:
69
2015-09-24
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
ta5
Member
Posts:
1,164
2015-09-28
Hi Marijn
Thx for the code. I'll give it a try!
Regards
Thomas
0
Sign In
or
Register
to comment.
Answers
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)
Senior NAV Developer
Elbek & Vejrup
Thx for your answers. Because there are already data existing, I'll opt for the "Magic Numbers"!
Regards
Thomas
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;
Thx for the code. I'll give it a try!
Regards
Thomas