|
<< Click to Display Table of Contents >> Navigation: Forum > TIWFileUploader OnAsyncUploadCompleted question |
03-14-2018, 11:07 PM:
In the documentation at http://docs.atozed.com/docs.dll/controls...oader.html, it says for OnAsyncUploadCompleted it says
Quote:This event is triggered when the file upload completes, BEFORE it is processed or saved by IntraWeb core. You should use this event to save the file to a different location, under a different name, or save it to a blob field in a TDataSet component
The method signatures make perfect sense, but there is no mention how I would grab the uploaded file stream to save it to a blob field before saving it to disk.
03-15-2018, 12:10 AM:
Hi Dave,
Here it goes. This was extracted from one of our demos here: https://github.com/Atozed/IntraWeb/tree/...UploaderDB
Code:
procedure TIWForm51.IWFileUploader1AsyncUploadCompleted(Sender: TObject; var DestPath,
FileName: string; var SaveFile, Overwrite: Boolean);
var
MS: TMemoryStream;
begin
// Create any TStream descendant
MS := TMemoryStream.Create;
try
// Save the file content to that stream
IWFileUploader1.SaveToStream(FileName, MS);
// inform IWFileUploader that we are handling it ourselves. No need to save the file
SaveFile := False;
// do whatever you want here with the TStream containing the file. For instance, save to the ClientDataSet
with ClientDataSet1 do begin
Append;
FieldByName('FileName').AsString := FileName;
FieldByName('FileSize').AsInteger := MS.Size;
// set to the start of the Stream
MS.Position := 0;
// save to the blob field
TBlobField(FieldByName('FileContent')).LoadFromStream(MS);
Post;
end;
finally
// Release the stream
MS.Free;
end;
end;
03-15-2018, 05:47 AM:
Thanks. I had no idea those demos were even there.