Hi all, having a slight problem with images stored on the db. We're having to store them in chunks so that we can run on an SQL back end
The code to store the image:
The code to drag it out again:
Now while the image file that is pulled back out again is loaded fine in a Crystal XI report, when we try and view the image in a normal image viewer we get messages to say it is corrupt. I've attached before and after files. The after is stored as a zip on here as it won't upload!!
Anyone have any bright ideas?!
The code to store the image:
Code:
/* convert the file into a memptr */
FILE-INFO:FILE-NAME = lvFile.
SET-SIZE(memptrCDoc) = FILE-INFO:FILE-SIZE.
INPUT FROM VALUE(lvFile) BINARY NO-CONVERT.
IMPORT memptrCDoc.
INPUT CLOSE.
/* Get the filename stripped of the path */
ASSIGN lvPos = R-INDEX(lvFile,"/").
IF lvPos EQ 0 OR lvPos EQ ? THEN
ASSIGN lvPos = R-INDEX(lvFile,"\").
IF lvPos GT 0 THEN
ASSIGN lvReference = SUBSTRING(lvFile, lvPos + 1).
/* Get the size of the document */
ASSIGN lvDocumentSize = GET-SIZE(memptrCDoc).
DO lvRecordCount = 1 TO lvDocumentSize BY {&DOCUMENT_PARTITION_SIZE}:
/* Set the raw data */
ASSIGN lvRawData = GET-BYTES(memptrCDoc, lvRecordCount, MINIMUM({&DOCUMENT_PARTITION_SIZE}, lvDocumentSize - lvRecordCount + 1)).
/* Create the record */
CREATE LABEL_IMAGE NO-ERROR.
IF ERROR-STATUS:ERROR THEN
DO:
RUN CREATE_ERROR_RECORD(INPUT "Unable to create image record","IMAGE_IMPORT").
LEAVE MAIN_BLOCK.
END.
ASSIGN
LABEL_IMAGE.ENTITY_MNEMONIC = "PIT"
LABEL_IMAGE.SOURCE_OBJECT_NUMBER = PACKAGED_ITEM.PACKAGED_ITEM_NUMBER
LABEL_IMAGE.IMAGE_NAME = lvReference.
&IF PROVERSION BEGINS "9" OR (DBTYPE("DB") EQ "Progress" OR DBTYPE("DB") EQ "OpenEdge") &THEN
ASSIGN LABEL_IMAGE.IMAGE = lvRawData.
&ELSE
ASSIGN LABEL_IMAGE.IMAGE = STRING(lvRawData).
&ENDIF
VALIDATE LABEL_IMAGE NO-ERROR.
IF ERROR-STATUS:ERROR THEN
DO:
RUN CREATE_ERROR_RECORD(INPUT "Unable to update image record","IMAGE_IMPORT").
LEAVE MAIN_BLOCK.
END.
RELEASE LABEL_IMAGE.
END.
RELEASE LABEL_IMAGE.
SET-SIZE(memptrCDoc) = 0.
LENGTH(lvRawData) = 0.
ASSIGN
memptrCDoc = ?
lvRawData = ?.
The code to drag it out again:
Code:
OUTPUT STREAM stImageFile TO VALUE(opFileName) BINARY NO-MAP NO-CONVERT.
FOR EACH LABEL_IMAGE NO-LOCK
WHERE LABEL_IMAGE.ENTITY_MNEMONIC EQ "PIT"
AND LABEL_IMAGE.SOURCE_OBJECT_NUMBER EQ PACKAGED_ITEM.PACKAGED_ITEM_NUMBER:
PUT STREAM stImageFile CONTROL LABEL_IMAGE.IMAGE.
END.
OUTPUT STREAM stImageFile CLOSE.
Now while the image file that is pulled back out again is loaded fine in a Crystal XI report, when we try and view the image in a normal image viewer we get messages to say it is corrupt. I've attached before and after files. The after is stored as a zip on here as it won't upload!!
Anyone have any bright ideas?!