#1 2014-03-29 14:56:45

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Save/restore file to/from database

I need save and restore some file from database.

This the code:

  TSQLDocuments = class(TSQLRecord)
  private
    ...
    fFilename: RawUTF8;
    fDocument: TSQLRawBlob;
    fSize: RawUTF8;
  published
    ...
    property Filename: RawUTF8 read fFilename write fFilename;
    property Document: TSQLRawBlob read fDocument write fDocument;
    property Size: RawUTF8 read fSize write fSize;
  end;

To save a file I use "StringFromFile" to convert it in RawByteString then I use UpdateBlob.
To restore I use "FileFromString" to extract file.

For my experience this way work only same type of file. For example I can save/restore TXT and DXF files but I cannot use it with PDF or JPG files, with PDF or JPG the restore file have 0 byte of size. I think these file are not save into database.

Is there error on my code?

NOTE. I have also try to use fDocument: RawUTF8;

regards

Last edited by array81 (2014-03-29 14:57:26)

Offline

#2 2014-03-29 16:10:06

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,183
Website

Re: Save/restore file to/from database

property Document: TSQLRawBlob sounds right to me.

This is how the main SynFile demo works... with no problem.

I suspect the problem is how you use it.
Remember that BLOB fields are not transmitted by default, unless you set ForceBlobTransfert property, or explicitly call UpdateBlobFields().

Offline

#3 2014-03-29 17:34:18

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Re: Save/restore file to/from database

The problem is that I use the same function and this work only for some file...

Offline

#4 2014-04-07 09:02:42

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,183
Website

Re: Save/restore file to/from database

I can't help you here, since we are not able to reproduce the issue...

Offline

#5 2014-04-07 16:05:31

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: Save/restore file to/from database

I use TSQLRawBlob so save/restore pdf file and .fr3 file (report) using explicit call to updateBlobField without problem.
Which kind of file cause the problem?i can test in my application.

Offline

Board footer

Powered by FluxBB