SaveToFile or LoadFromFile problem

Hi,
I use the following code to save the file into DB.

tbl_master.FieldByName(‘SYS_File’).LoadFromFile(FileFullName);

But I use SaveToFile to download the file from DB. The file is corrupted. I use this in existing project without problem. It doesn’t work in DA. How to solve it?

Can you give a bit more context on this? I’m not sure I understand how LoadFromFile can be called on a field? what are you trying to accomplish here, loading the binary data of the file into the SYS_File field on the currently active record? what is the field type, and how exactly does the data get corrupted?

Hi,
Yes. It is loading the binary data of the file into SYS_File field. SQL table field is varbinary. I’m using the following code in existing application that works fine. It is a SDAC component.

InsertSys.Active := false;
InsertSys.ParamByName('SYS_File').DataType := ftBlob;
InsertSys.ParamByName('SYS_Flag').Value := Sys_Flag;
InsertSys.ParamByName('SYS_File').LoadFromFile(edtFileName.Text, ftBlob);
InsertSys.ParamByName('File_Name').Value := ChangeFileExt(ExtractFileName(edtFileName.Text),'');
InsertSys.ParamByName('File_Ext').Value := ExtractFileExt(edtFileName.Text);
InsertSys.ParamByName('File_Age').AsDateTime := FileDateToDateTime(FileAge(edtFileName.Text));
InsertSys.ParamByName('File_Path').Value := edt_FilePath.Text;
InsertSys.ParamByName('File_Size').Value := 0;
InsertSys.Execute;

And using the following code to save the file. All code is handling “Application and files update automatically”. I don’t want to using URL for application update because it needs to have IIS setup. So I write the function to handle the application update.

dm_main.msqry_sysfileSYS_File.SaveToFile(ExtractFilePath(Application.ExeName) + dm_main.msqry_sysfile.FieldByName(‘File_Path’).AsWideString + dm_main.msqry_sysfile.FieldByName(‘File_Name’).AsWideString + dm_main.msqry_sysfile.FieldByName(‘File_Ext’).AsWideString);

Hmm, Blob sound right. if yu don

InsertSys.ParamByName('SYS_File').LoadFromFile(edtFileName.Text, ftBlob);
InsertSys.ParamByName('SYS_File').SaveToFile("temp.file", ftBlob);

right away, is it already corrupted? or only of you gets sent to the server and retrieved later? How does the corruption look? is it cut off? it the data changed? what

Hi,
DAMemDataTable’s LoadFromFile & SaveToFile without “ftBlob” parameter. I don’t know the upload to DB that already corrupt or save to local that corrupt. I don’t know how to check the problem is upload or download. The other solution is using your demo “ExtendedFileTransfer” and “File Broadcast” that replace my existing approach.

If using “Extended File Transfer” and “File Broadcast”, it will facing the file lock when update the files because application is running under RDP in other countries.

Well, as i suggested, just insert this one line right after the load

InsertSys.ParamByName('SYS_File').LoadFromFile(edtFileName.Text, ftBlob);
InsertSys.ParamByName('SYS_File').SaveToFile("C:\temp.file", ftBlob);

is C:\temp.file corrupt or not? Also:

Hi,
EXE file doesn’t work after savetofile. I tried to using the past records and savetofile. EXE file also doesn’t work. If INI file, the content is changed.
I’m not using “DA Command” to insert the record. I’m using DAMemDataTable.Append for insert the record. Is it different result?

Ok, that does sound like a bug. I’ll log. How does it change? what’s the nature of the corruption? can you post (or send via private message) a good and bad file for comparison? thanx!

Logged as bugs://D19133.

Hi,
I sent the email for you with attachments. Please check it.

Hi,

Here is the example. “Connect(From DA).ini” is using savetofile. The other file is using my existing appliction to update the file to DB table.

Thanks & regards,

Timothy

(Attachment Connect.ini is missing)

(Attachment Connect(From DA).ini is missing)

Hi,
Your email server reject the attachments. I zip it and resent it again.
Thanks

Hi,

Here is the example. “Connect(From DA).ini” is using savetofile. The other file is using my existing appliction to update the file to DB table.

Thanks & regards,

Timothy

fileSample.zip (1.95 KB)

Curious:

It seems that SaveToFile does not just save the blob content, but all the data of the field, in DABIN2 format (thats the format sued for over the wire streaming).

This sure does sound like a bug (or we’re misunderstanding whether LoadFromFile/SaveToFile is supposed to be used for this), I’ll have Eugene have a look tomorrow.

Noted with thanks

1 Like

Hi,

looks like you have saved whole table to file instead of field.
you should use something like

DAMemDataTable1.Fields[0].SaveToFile('Connect (saved).ini');

instead of

DAMemDataTable1.SaveToFile('Connect (saved).ini');

check my testcase: 25240.zip (24.9 KB)

bugs://D19133 was closed as no change required.

Hi,
Yes, You’re right. The problem solved. Thanks!

1 Like