Subject | Re: AW: [IBO] Re: Storing PDF into Firebird Blobs |
---|---|
Author | Terry Black |
Post date | 2012-05-21T11:35:22Z |
Hi Herbert, If I use WriteFromFileToBlob('C:\db\dell.pdf', DM.qrScan.FieldByName('PDFIMAGE'));
this puts the PDF file into the blob, but I am having trouble getting it out and displaying it.
If I try the reverse
procedure TfrMain.Button5Click(Sender: TObject);
var xxx:string;
begin
ReadFromBlobToFile(DM.qrScan.FieldByName('PDFIMAGE'),xxx);
end;
it does not work.
Terry
Terry Black
IT Manager
Northern Sydney Central Coast
Public Health Unit (Hornsby Office)
I use some functions to do that.
The first function reads from file fromFile and writes to
IB_Column toField.
function WriteFromFileToBlob(fromFile: string; toField: TIB_Column):
Boolean;
var
fStream: TFileStream;
blobStream: TIB_BlobStream;
begin
Result := False;
fStream := TFileStream.Create(fromFile, fmOpenRead or fmShareDenyNone);
blobStream := TIB_BlobStream.CreateForColumn(toField, bsmWrite);
try
Result := blobStream.CopyFrom(fStream, fStream.Size) > 0;
finally
FreeAndNil(blobStream);
FreeAndNil(fStream);
end;
end;
The second function reads from stream fromSteam and writes to
IB_Column.
function WriteFromStreamToBlob(fromStream: TStream; toField: TIB_Column):
Boolean;
var
blobStream: TIB_BlobStream;
begin
Result := False;
blobStream := TIB_BlobStream.CreateForColumn(toField, bsmWrite);
try
Result := blobStream.CopyFrom(fromStream, fromStream.Size) > 0;
finally
FreeAndNil(blobStream);
end;
end;
Reading from a blob into a stream or a file is just the other way round:
function ReadFromBlobToStream(AField: TIB_Column; toStream: TStream):
Boolean;
var
blobStream: TIB_BlobStream;
begin
Result := AField.IsNotNull;
if Result then
begin
blobStream := TIB_BlobStream.CreateForColumn(AField, bsmRead);
try
Result := toStream.CopyFrom(blobStream, blobStream.Size) > 0;
finally
FreeAndNil(blobStream);
end;
end;
end;
function ReadFromBlobToFile(AField: TIB_Column; fileName: string): Boolean;
var
blobStream: TIB_BlobStream;
fStream: TFileStream;
begin
Result := AField.IsNotNull;
if Result then
begin
blobStream := TIB_BlobStream.CreateForColumn(AField, bsmRead);
fStream := TFileStream.Create(fileName, fmOpenWrite or
fmShareDenyWrite);
try
Result := fStream.CopyFrom(blobStream, blobStream.Size) > 0;
finally
FreeAndNil(fStream);
FreeAndNil(blobStream);
end;
end;
end;
In your case, I would call the function
WriteFromFileToBlob(PDFFileName, TargetColumn);
Hope this helps.
Herbert
If I look at the Help file it gives some code for using CreateBlobStream but
I am unable to get it to work.
Has anyone another example I could use.
Terry
[Non-text portions of this message have been removed]
Disclaimer: This message is intended for the addressee named and may contain confidential information. If you are not the intended recipient, please delete it and notify the sender.
Views expressed in this message are those of the individual sender, and are not necessarily the views of the Local Health District or associated entities.
this puts the PDF file into the blob, but I am having trouble getting it out and displaying it.
If I try the reverse
procedure TfrMain.Button5Click(Sender: TObject);
var xxx:string;
begin
ReadFromBlobToFile(DM.qrScan.FieldByName('PDFIMAGE'),xxx);
end;
it does not work.
Terry
Terry Black
IT Manager
Northern Sydney Central Coast
Public Health Unit (Hornsby Office)
>>> "Herbert Senner" <hsenner@...> 21/05/12 3:57 AM >>>Hi Terry,
I use some functions to do that.
The first function reads from file fromFile and writes to
IB_Column toField.
function WriteFromFileToBlob(fromFile: string; toField: TIB_Column):
Boolean;
var
fStream: TFileStream;
blobStream: TIB_BlobStream;
begin
Result := False;
fStream := TFileStream.Create(fromFile, fmOpenRead or fmShareDenyNone);
blobStream := TIB_BlobStream.CreateForColumn(toField, bsmWrite);
try
Result := blobStream.CopyFrom(fStream, fStream.Size) > 0;
finally
FreeAndNil(blobStream);
FreeAndNil(fStream);
end;
end;
The second function reads from stream fromSteam and writes to
IB_Column.
function WriteFromStreamToBlob(fromStream: TStream; toField: TIB_Column):
Boolean;
var
blobStream: TIB_BlobStream;
begin
Result := False;
blobStream := TIB_BlobStream.CreateForColumn(toField, bsmWrite);
try
Result := blobStream.CopyFrom(fromStream, fromStream.Size) > 0;
finally
FreeAndNil(blobStream);
end;
end;
Reading from a blob into a stream or a file is just the other way round:
function ReadFromBlobToStream(AField: TIB_Column; toStream: TStream):
Boolean;
var
blobStream: TIB_BlobStream;
begin
Result := AField.IsNotNull;
if Result then
begin
blobStream := TIB_BlobStream.CreateForColumn(AField, bsmRead);
try
Result := toStream.CopyFrom(blobStream, blobStream.Size) > 0;
finally
FreeAndNil(blobStream);
end;
end;
end;
function ReadFromBlobToFile(AField: TIB_Column; fileName: string): Boolean;
var
blobStream: TIB_BlobStream;
fStream: TFileStream;
begin
Result := AField.IsNotNull;
if Result then
begin
blobStream := TIB_BlobStream.CreateForColumn(AField, bsmRead);
fStream := TFileStream.Create(fileName, fmOpenWrite or
fmShareDenyWrite);
try
Result := fStream.CopyFrom(blobStream, blobStream.Size) > 0;
finally
FreeAndNil(fStream);
FreeAndNil(blobStream);
end;
end;
end;
In your case, I would call the function
WriteFromFileToBlob(PDFFileName, TargetColumn);
Hope this helps.
Herbert
If I look at the Help file it gives some code for using CreateBlobStream but
I am unable to get it to work.
Has anyone another example I could use.
Terry
[Non-text portions of this message have been removed]
Disclaimer: This message is intended for the addressee named and may contain confidential information. If you are not the intended recipient, please delete it and notify the sender.
Views expressed in this message are those of the individual sender, and are not necessarily the views of the Local Health District or associated entities.