Subject | AW: [IBO] Re: Storing PDF into Firebird Blobs |
---|---|
Author | Terry Black |
Post date | 2012-05-20T22:19:10Z |
Thanks
I will try what you have sent to me.
Terry
IT Manager | Public Health Unit Hornsby | Health Reform Transitional Organisation Northern
Hornsby Hospital, Main Building 1, 36-76 Palmerston Road, Hornsby NSW 2077
Tel. 02 9477 9400 | Fax. 02 9482 1650 | tblac@...
www.health.nsw.gov.au
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.
I will try what you have sent to me.
Terry
IT Manager | Public Health Unit Hornsby | Health Reform Transitional Organisation Northern
Hornsby Hospital, Main Building 1, 36-76 Palmerston Road, Hornsby NSW 2077
Tel. 02 9477 9400 | Fax. 02 9482 1650 | tblac@...
www.health.nsw.gov.au
>>> "Herbert Senner" <hsenner@...> 21/05/2012 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.