From d00ec4555f81210cd067f98d9bc7cef51f456462 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 7 Jun 2008 00:28:49 +0200 Subject: experimental Flash based multi upload This patch adds experimental support for uploading multiple files in one go. This is achieved by using Flash for selecting multiple images and intitiating the HTTP upload. When Flash 8 or higher is detected, an additional icon is added to the usual upload form. Clicking it will swith the form to the Flash based upload queue. Things that need work: * Better Icon * Feedback if Flash detection works on all Flash 8 supported platforms * Progress feedback seems not to work on Linux (might be Adobe bug) * No final feedback how many images were uploaded correctly The flash sources are located in lib/_fla/ Any feedback and help would be appreciated. darcs-hash:20080606222849-7ad00-738083445af275752aaebc29bfa51430f3d94459.gz --- lib/_fla/.htaccess | 3 + lib/_fla/MultipleUpload.as | 274 ++++++++++++++++++++++++++++++++++++++++++++ lib/_fla/README | 1 + lib/_fla/multipleUpload.fla | Bin 0 -> 1812992 bytes 4 files changed, 278 insertions(+) create mode 100644 lib/_fla/.htaccess create mode 100644 lib/_fla/MultipleUpload.as create mode 100644 lib/_fla/README create mode 100644 lib/_fla/multipleUpload.fla (limited to 'lib/_fla') diff --git a/lib/_fla/.htaccess b/lib/_fla/.htaccess new file mode 100644 index 000000000..9a7d38c12 --- /dev/null +++ b/lib/_fla/.htaccess @@ -0,0 +1,3 @@ +## no access to the fla directory +order allow,deny +deny from all diff --git a/lib/_fla/MultipleUpload.as b/lib/_fla/MultipleUpload.as new file mode 100644 index 000000000..8e7e0b008 --- /dev/null +++ b/lib/_fla/MultipleUpload.as @@ -0,0 +1,274 @@ +/** + * Flash Multi Upload + * + * Based on a example from Alastair Dawson + * + * @link http://blog.vixiom.com/2006/09/08/multiple-file-upload-with-flash-and-ruby-on-rails/ + * @author Alastair Dawson + * @author Andreas Gohr + */ + +// delegate +import mx.utils.Delegate; +// ui components +import mx.controls.DataGrid; +import mx.controls.gridclasses.DataGridColumn +import mx.controls.Button; +import mx.controls.TextInput; +import mx.controls.CheckBox; +import mx.controls.Label; +// file reference +import flash.net.FileReferenceList; +import flash.net.FileReference; + +class MultipleUpload { + + private var fileRef:FileReferenceList; + private var fileRefListener:Object; + private var list:Array; + private var dp:Array; + + private var files_dg:DataGrid; + private var browse_btn:Button; + private var upload_btn:Button; + private var ns_input:TextInput; + private var ns_label:Label; + private var overwrite_cb:CheckBox; + + /** + * Constructor. + * + * Initializes the needed objects and stage objects + */ + public function MultipleUpload(fdg:DataGrid, bb:Button, ub:Button, nsi:TextInput, nsl:Label, ob:CheckBox) { + // references for objects on the stage + files_dg = fdg; + browse_btn = bb; + upload_btn = ub; + ns_input = nsi; + ns_label = nsl; + overwrite_cb = ob; + + // file list references & listener + fileRef = new FileReferenceList(); + fileRefListener = new Object(); + fileRef.addListener(fileRefListener); + + // setup + iniUI(); + inifileRefListener(); + } + + /** + * Initializes the User Interface + * + * Uses flashvars to access possibly localized names + */ + private function iniUI() { + // register button handlers + browse_btn.onRelease = Delegate.create(this, this.browse); + upload_btn.onRelease = Delegate.create(this, this.upload); + + // columns for dataGrid + var col:DataGridColumn; + col = new DataGridColumn('name'); + col.headerText = ( _root.L_gridname ? _root.L_gridname : 'Filename' ); + col.sortable = false; + files_dg.addColumn(col); + col = new DataGridColumn('size'); + col.headerText = ( _root.L_gridsize ? _root.L_gridsize : 'Size' ); + col.sortable = false; + files_dg.addColumn(col); + col = new DataGridColumn('status'); + col.headerText = ( _root.L_gridstat ? _root.L_gridstat : 'Status' ); + col.sortable = false; + files_dg.addColumn(col); + + // label translations + if(_root.L_overwrite) overwrite_cb.label = _root.L_overwrite; + if(_root.L_browse) browse_btn.label = _root.L_browse; + if(_root.L_upload) upload_btn.label = _root.L_upload; + if(_root.L_namespace) ns_label.text = _root.L_namespace; + + // prefill input field + if(_root.O_ns) ns_input.text = _root.O_ns; + + // disable buttons + upload_btn.enabled = false; + if(!_root.O_overwrite) overwrite_cb.visible = false; + + // initalize the data provider list + dp = new Array(); + list = new Array(); + files_dg.spaceColumnsEqually(); + } + + /** + * Open files selection dialog + * + * Adds the allowed file types + */ + private function browse() { + if(_root.O_extensions){ + var exts:Array = _root.O_extensions.split('|'); + var filter:Object = new Object(); + filter.description = (_root.L_filetypes ? _root.L_filetypes : 'Allowed filetypes'); + filter.extension = ''; + for(var i:Number = 0; i _root.O_maxsize){ + stat = (_root.L_toobig ? _root.L_toobig : 'too big'); + }else{ + stat = (_root.L_ready ? _root.L_ready : 'ready for upload'); + } + // add to grid + dp.push({name:sel[i].name, size:Math.round(sel[i].size / 1000) + " kb", status:stat}); + // add to reference list + list.push(sel[i]); + } + // update dataGrid + files_dg.dataProvider = dp; + files_dg.spaceColumnsEqually(); + + if(list.length > 0) upload_btn.enabled = true; + } + + /** + * Does nothing + */ + private function onCancel() { + } + + /** + * Does nothing + */ + private function onOpen(file:FileReference) { + } + + /** + * Set the upload progress + */ + private function onProgress(file:FileReference, bytesLoaded:Number, bytesTotal:Number) { + var percentDone = Math.round((bytesLoaded / bytesTotal) * 100); + var msg:String = 'uploading @PCT@%'; + if(_root.L_progress) msg = _root.L_progress; + msg = msg.split('@PCT@').join(percentDone); + this.setStatus(file,msg); + } + + /** + * Handle upload completion + */ + private function onComplete(file:FileReference) { + this.setStatus(file,(_root.L_done ? _root.L_done : 'complete')); + } + + /** + * Handle upload errors + */ + private function onHTTPError(file:FileReference, httpError:Number) { + if(httpError == 400){ + this.setStatus(file,(_root.L_fail ? _root.L_fail : 'failed')); + }else if(httpError == 401){ + this.setStatus(file,(_root.L_authfail ? _root.L_authfail : 'auth failed')); + }else{ + this.setStatus(file,"HTTP Error " + httpError); + } + } + + /** + * Handle IO errors + */ + private function onIOError(file:FileReference) { + this.setStatus(file,"IO Error"); + } + + /** + * Handle Security errors + */ + private function onSecurityError(file:FileReference, errorString:String) { + this.setStatus(file,"SecurityError: " + errorString); + } + + +} diff --git a/lib/_fla/README b/lib/_fla/README new file mode 100644 index 000000000..beaa15d02 --- /dev/null +++ b/lib/_fla/README @@ -0,0 +1 @@ +Flash source files. Those will not be included in the tarball releases. diff --git a/lib/_fla/multipleUpload.fla b/lib/_fla/multipleUpload.fla new file mode 100644 index 000000000..a04237c1c Binary files /dev/null and b/lib/_fla/multipleUpload.fla differ -- cgit v1.2.3