Unit Unit7;
Interface
Uses
Classes, Sysutils, Iwappform, Iwapplication, Iwcolor, Iwtypes, Vcl.controls,
Iwvclbasecontrol, Iwbasecontrol, Iwbasehtmlcontrol, Iwcontrol,
Iwcompfileuploader, Iwcomplabel, data.db, datasnap.dbclient;
Type
TIWFORM7 = Class (Tiwappform)
Iwfileuploader1:tiwfileuploader;
Iwlabel1:tiwlabel;
Iwlabel2:tiwlabel;
Iwfileuploader2:tiwfileuploader;
Iwlabel3:tiwlabel;
Iwfileuploader3:tiwfileuploader;
Clientdataset1:tclientdataset;
Clientdataset1filename:tstringfield;
Clientdataset1filesize:tintegerfield;
Clientdataset1filecontent:tblobfield;
Iwlabel4:tiwlabel;
Iwfileuploader4:tiwfileuploader;
Procedure iwfileuploader1asyncuploadcompleted (Sender:tobject; var destpath,
filename:string; var SaveFile, Overwrite:boolean);
Procedure iwfileuploader2asyncuploadcompleted (Sender:tobject; var destpath,
filename:string; var SaveFile, Overwrite:boolean);
Procedure iwfileuploader3asyncuploadcompleted (Sender:tobject; var destpath,
filename:string; var SaveFile, Overwrite:boolean);
Procedure Iwappformcreate (Sender:tobject);
Public
End
Implementation
{$R *.DFM}
Uses
IW.Common.AppInfo;
Procedure Tiwform7.iwappformcreate (Sender:tobject);
Begin
Create The DataSet so we can use it later
Clientdataset1.createdataset;
End
Procedure tiwform7.iwfileuploader1asyncuploadcompleted (Sender:tobject;
var destpath, filename:string; var SaveFile, Overwrite:boolean);
Var
curdir:string;
Begin
Get the app Path
CurDir: = Tiwappinfo.getapppath;
Save in the same application directory, with the same name of the the original file. Overwrite if it already exists.
Iwfileuploader1.savetofile (filename, CurDir + filename, True);
Inform Iwfileuploader that we is taking care of file saving ourselves
SaveFile: = False;
End
Procedure tiwform7.iwfileuploader2asyncuploadcompleted (Sender:tobject;
var destpath, filename:string; var SaveFile, Overwrite:boolean);
Begin
Here we just inform the new name for the file. Iwfileuploader'll take care of the rest.
The file would be saved inside the user cache directory (WEBAPPLICATION.USERCACHEDIR)
FileName: = ' MyUploadedFile.dat ';
End
Procedure tiwform7.iwfileuploader3asyncuploadcompleted (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 the stream
Iwfileuploader3.savetostream (FileName, MS);
Inform Iwfileuploader that we are handling it ourselves. No need to save the file
SaveFile: = False;
Do whatever your 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
Initialization
Tiwform7.setasmainform;
End.
Iwfileuploader official Demo