使用 IntraWeb (24) - 基本控件之 TIWFileUploader、TIWFile

TIWFileUploader 是基于 Ajax 的上传控件, 最初是 Andrew Valums 开发, 从 IntraWeb XIV 纳入并替换 TIWFile.

虽然从组件面板上还能看到 TIWFile, 官方说已不能使用.

现在的 TIWFileUploader 非常方便, 能拖拽上传, 能批量上传, 会自动显示上传进度, 界面也可以很漂亮.

我测试拖拽上传时, 发现有些浏览器不支持.


TIWFileUploader 所在单元及继承链:
IWCompFileUploader.TIWFileUploader

主要成员:


property MaxFileSize: Int64      //文件最大许可, 默认 20971520(20MB); 如果为 0, 则表示没有最大限制
property MinFileSize: Int64      //文件最小许可, 默认 0, 表示没有最小限制
property Multiple: Boolean       //是否支持多个文件同时上传, 默认 False
property AutoHideListTime: Cardinal  //上传后等待多少毫秒既隐藏上传列表; 默认 0, 表示不隐藏.
property TextStrings: TIWFileUploaderTextStrings //这包含 12 项信息文本, 可以通过它彻底地本地化
property Style: TIWFileUploaderStyle //它包含 7 个子选项, 可设置各种状态下的样式, 能弄得很漂亮
property AllowedExtensions: string   //支持上传的文件类型, 多种类型用逗号分割, 如: rar,zip,pdf,mp3; 默认为空, 表示支持任何文件
property AutoSave: Boolean      //上传完成后是否自动保存到 AutoSavePath 指示的文件夹
property AutoSavePath: string   //用于自动保存的文件夹, 如果不存在会创建; 如果出错会保存在用户的缓存文件夹
property OverwriteExisting: Boolean  //是否覆盖同名文件, 默认 True; False 时遇同名会引发异常
property DisableCancel: Boolean	//在上传过程中, 是否禁用"取消", 默认 False
property FileList: THttpFileList //?
property AcceptFiles: string	 //?

property OnAsyncUploadCompleted: TUploadCompleteEvent //该事件在上传完毕后自动保存前触发; 可以在该事件中更改路径或文件名, 甚至取消保存
property OnAsyncUploadSuccess: TIWAsyncEvent	      //成功完成后
property OnAsyncUploadError: TIWAsyncEvent	      //出错时

{下面三个保存方法都应该用在 OnAsyncUploadCompleted 中}
function SaveAll(APathname: string; AOverwrite: Boolean)  //如果还是使用源文件名, 应该用这个
function SaveToFile(ASourceFileName: string; ADestFileName: TFileName; AOverwrite: Boolean) //假如要更改文件名, 用这个
function SaveToStream(ASourceFileName: string; AStream: TStream)  //
procedure NotifyUploadCompleted	//

测试 1(全自动上传):


uses ServerController;

procedure TIWForm1.IWAppFormCreate(Sender: TObject);
begin
  IWFileUploader1.MaxFileSize := 0; //不限制大文件
  IWFileUploader1.Multiple := True; //可以同时上传多个文件
  IWFileUploader1.AutoSave := True; //自动保存
  IWFileUploader1.AutoSavePath := IWServerController.ContentPath; //这是 wwwroot, 需要修改文件夹属性, 可写才行
end;

测试 2(在 OnUploadCompleted 事件中保存):


uses ServerController;

procedure TIWForm1.IWAppFormCreate(Sender: TObject);
begin
  IWFileUploader1.MaxFileSize := 0;
  IWFileUploader1.Multiple := True;
  IWFileUploader1.AutoSavePath := IWServerController.ContentPath;
end;

//OnUploadCompleted 的参数解释:
//DestPath 同 AutoSavePath
//FileName 同源文件名
//SaveFile 它会是 True,
//Overwrite 同 OverwriteExisting
procedure TIWForm1.IWFileUploader1AsyncUploadCompleted(Sender: TObject; var DestPath, FileName: string; var SaveFile, Overwrite: Boolean);
begin
  IWFileUploader1.SaveAll(DestPath, Overwrite);
  SaveFile := False; //如果前面设置了自动保存, 就取消它
end;

转帖几张官方的图片吧:







使用 IntraWeb (24) - 基本控件之 TIWFileUploader、TIWFile

时间: 2024-07-30 06:23:07

使用 IntraWeb (24) - 基本控件之 TIWFileUploader、TIWFile的相关文章

使用 IntraWeb (28) - 基本控件之 TIWTemplateProcessorHTML、TIWLayoutMgrHTML、TIWLayoutMgrForm

TIWTemplateProcessorHTML //使用外部的 html 文件做模板 TIWLayoutMgrHTML //直接输入 Html 文本做模板 TIWLayoutMgrForm //这应该只是内部使用的东西, 对用户没有意义 {需要把它们关联到窗体的 LayoutMgr 属性; 主模板需要通过 IWServerController.MasterTemplate 指定} TIWTemplateProcessorHTML 所在单元及继承链: IWTemplateProcessorHTM

使用 IntraWeb (26) - 基本控件之 TIWMenu

TIWMenu 的任务是让原来的 TMainMenu 呈现在网页上, 通过其 AttachedMenu 属性关联一个 TMainMenu 是必需的. TIWMenu 所在单元及继承链: IWCompMenu.TIWMenu 主要成员: property TextOffset: Integer //菜单文本偏移(只读) property AttachedMenu: TMainMenu //指定要包装的 TMainMenu property ItemSpacing: TIWSpaceItems //

使用 IntraWeb (13) - 基本控件之 TIWLabel、TIWLink、TIWURL、TIWURLWindow

TIWLabel    // TIWLink      //内部链接 TIWURL      //外部链接 TIWURLWindow //页内框架, 就是 <iframe></iframe> TIWLabel 所在单元及继承链:IWCompLabel.TIWLabel < TIWCustomLabel < TIWCustomControl < TIWBaseHTMLControl < TIWBaseControl < TIWVCLBaseControl

使用 IntraWeb (16) - 基本控件之 TIWList、TIWListbox、TIWComboBox、TIWOrderedListbox

TIWList //列表; 它对应 Html 中的 OL.LI(某些选项下会用表格模拟); TIWListbox 和 TIWComboBox 则对应 Html 在的 Option TIWListbox //列表框 TIWComboBox //组合下拉框 TIWOrderedListbox //可手动调整顺序的列表; 好像是新增的, 还不成熟 TIWList 所在单元及继承链: IWHTMLControls.TIWList 主要成员: property Items: TStringList //

使用 IntraWeb (22) - 基本控件之 TIWCalendar

TIWCalendar: 日历控件, 继承于 TIWCustomGrid, 所以它和 TIWGrid 共同属性特多. 它的 Cell 是 TIWCalendarCell 对象, 直接从 TIWGridCell 继承. TIWCalendar 所在单元及继承链: IWCompCalendar.TIWCalendar 主要成员: property Cell[const ARow: Integer, const AColumn: Integer]: TIWCalendarCell // propert

使用 IntraWeb (23) - 基本控件之 TIWTimer、TIWProgressBar、TIWProgressIndicator、TIWTimeEdit

TIWTimer //和 TTimer 没多大区别, 它的默认事件现在是异步的(OnAsyncTimer), 在网络上使用 OnTimer 肯定是非常糟糕的 TIWProgressBar //进度条 TIWProgressIndicator //进度提示器; 这是个新东西, 非常好; 当碰到时间较长的加载时(同步或异步)都可以用用; 使用前需要先关联到窗体的 ProgressIndicator 属性 TIWTimeEdit //个人认为这个东西一点用也没有; 只是给个分钟数按 8 小时换算成天.

使用 IntraWeb (17) - 基本控件之 TIWRadioButton、TIWRadioGroup、TIWCheckBox

TIWRadioButton //单选 TIWRadioGroup //单选组 TIWCheckBox //复选 TIWRadioButton 所在单元及继承链: IWCompRadioButton.TIWRadioButton 主要成员: property Editable: Boolean // property Checked: Boolean // property Group: string //分组名; 在统一母体中的单选按钮, 组名相同者互斥 property Value: str

使用 IntraWeb (25) - 基本控件之 TIWRegion

这应该是 IW 中最重要的容器了, 和它同父的还有 TIWTabControl TIWRegion 所在单元及继承链: IWRegion.TIWRegion 主要成员: property Align: TAlign property Anchors: TAnchors property BorderOptions: TIWContainerBorderOptions //设置边框的宽度.颜色.样式 property Color: TIWColor property ClipRegion: Boo

使用 IntraWeb (21) - 基本控件之 TIWTabControl

TIWTabControl 包含的是 TIWTabPage; 设计时通过右键菜单 Add Page 添加(再给页面添加东西时一定要先选定页面); 下面例子是动态添加的. TIWTabControl 所在单元及继承链: IWCompTabControl.TIWTabControl 主要成员: property Pages: TList //TIWTabPage 对象的集合; 但它是 TList 类型, 使用前需转换下 property ActiveTabFont: TIWFont //当前 Tab