KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Using BLOB TO PICTURE with pictures uploaded from a browser
PRODUCT: 4D | VERSION: 2004 | PLATFORM: Mac & Win
Published On: October 21, 2004
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

When using the command BLOB TO PICTURE with a picture uploaded from a browser, the BLOB has header data causing the command BLOB TO PICTURE to return 0. To avoid this problem, the BLOB needs to be stripped of its header contents before you convert the BLOB to a picture. The following code below will strip the header and convert it to a picture.

`Strip header method

If (BLOB size(myfile)>0)
C_STRING(255;$fileHeader)
$offset:=0
$fileHeader:=BLOB to text(myfile;Text without length ;$offset;255)
$fileNameBegin:=Position("filename=";$fileHeader)+10
For ($i;$fileNameBegin;255)
If ($fileHeader[[$i]]=Char(Double quote ))
$fileNameEnd:=$i
$i:=255
End if
End for
$fileName:=Substring($fileHeader;$fileNameBegin;$fileNameEnd-$fileNameBegin)
$contentTypeBegin:=Position("Content-Type:";$fileHeader)+14
For ($i;$contentTypeBegin;255)
If ($fileHeader[[$i]]=Char(Carriage return ))
$contentTypeEnd:=$i
$i:=255
End if
End for
contentType:=Substring($fileHeader;$contentTypeBegin;$contentTypeEnd-$contentTypeBegin)
DELETE FROM BLOB(myfile;0;$contentTypeEnd+3)
CREATE RECORD([Table 1])
BLOB TO PICTURE(myfile;[Table 1]Field2)
SAVE RECORD([Table 1])