Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TIWFileUploader OnAsyncUploadCompleted question
#1
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.
Reply
#2
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;
Reply
#3
Thanks. I had no idea those demos were even there.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)