Add binary to existing BLOB

mkontou

New Member
Does anybody know if is possible to modify BLOB data so you can add pages to the scanned document?

We save scanned documents in a database table as blob. Today we need to be able to have additional pages added to the exisitng BLOB records. Is that possible in anyway?

Thanks.
 

sdjensen

Member
That depends on how you load the pages into the db.

Load the first page into a memptr.
save the length of the memptr somewhere in your record so you know how long the first page is.
load the second page to a new memptr and save the length of this page as well.
load the thrid page to a new memptr and save the length of this page as well.

combine the three memptr's into one and upload that one to your db.
Also remember so save the length of the pages.

When you need to retrieve the pages, then load the memptr based on the saved lengths.
 

sdjensen

Member
Code:
define variable m1 as memptr.
define variable m2 as memptr.
define variable cc1 as character no-undo.
cc1 = 'string1'.
define variable cc2 as character no-undo.
cc2 = 'string2'.
define variable l as integer no-undo.
l = length(cc1) + 1.
set-size(m1) = length(cc1) + 1.
set-size(m2) = length(cc2) + 1.
put-string(m1,1) = cc1.
put-string(m2,1) = cc2.

define variable m3 as memptr.
set-size(m3) = get-size(m1) + get-size(m2).
define variable idx as integer no-undo.
do idx = 1 to get-size(m1):
  put-byte(m3,idx) = get-byte(m1,idx).    
end.
do idx = 1 to get-size(m2):
  put-byte(m3,idx + l) = get-byte(m2,idx).    
end.

cc1 = ''.
cc2 = ''.
cc1 = get-string(m3,1,l).
cc2 = get-string(m3,l + 1).
message cc1 skip cc2 view-as alert-box.
set-size(m3) = 0.
set-size(m1) = 0.
set-size(m2) = 0.

I am not sure if this is the best way to do it but test it to see if it works for you. :awink:
 

mkontou

New Member
May thanks for all your help. I have tried many ways with out success. Trying the code you provided, I get the output file, under my directory bur unable to open it. This is what I am trying.

def var m1 as memptr.
def var l1 as int.
def var m2 as memptr.
def var l2 as int.
def var m3 as memptr.
def var l3 as int.


def var newm as memptr.
define variable idx as integer no-undo.


file-info:file-name = "filename1.jpg".
set-size(m1) = file-info:file-size + 1.
l1 = get-size(m1).


input from "filename1.jpg" binary no-map no-convert.
import m1.
input close.


file-info:file-name = "filename2.jpg".
set-size(m2) = file-info:file-size + 1.
l2 = get-size(m2).


input from "filename2.jpg" binary no-map no-convert.
import m2.
input close.


file-info:file-name = "filename3.jpg".
set-size(m3) = file-info:file-size + 1.
l3 = get-size(m3).


input from "filename3.jpg" binary no-map no-convert.
import m3.
input close.


set-size(newm) = l1 + l2 + l3.

do idx = 1 to get-size(m1):
put-byte(newm,idx) = get-byte(m1,idx).
end.


do idx = 1 to get-size(m2):
put-byte(newm,idx + 1) = get-byte(m2,idx).
end.


do idx = 1 to get-size(m2):
put-byte(newm,idx + 1) = get-byte(m3,idx).
end.


OUTPUT TO "newfile.jpg" BINARY.
EXPORT newm.
OUTPUT CLOSE.


assign
set-size(m1) = 0
set-size(m2) = 0
set-size(m3) = 0
set-size(newm) = 0.


Any ideas? The file newfile.jpg is created, it has size under windows but I can not open it.
 

sdjensen

Member
Hi,

First
do idx = 1 to get-size(m2):
put-byte(newm,idx + 1) = get-byte(m3,idx).
end.
Should be
Code:
do idx = 1 to get-size(m3): /* note the m3 instead of m2 ;) */
put-byte(newm,idx + 1) = get-byte(m3,idx). 
end.

OUTPUT TO "newfile.jpg" BINARY.
EXPORT newm.
OUTPUT CLOSE.

Your 'newm' memptr contains all three images but you cannot output it as one image.
Save newm in your database and when you need to retrieve the image,
use the length to find out where in your memptr your image is.

If you are trying to combine the images to one image then you will need to look elsewhere as I have not idea on how this is done in Progress
 
Top