Files
Clemens Schwaighofer 32455459da AJAX simple file uploader
A simple javascript powered file uploader with progress and hooks
support.

Was created as a loose replacement for FineUploader.
Currently only works with local uploads

Below is the log history from the previous folder:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
commit 6ea59f91314be8b2b936920d4b0a3f04932c9e73 ┃
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━
Author: Clemens Schwaighofer <clemens.schwaighofer@egplusww.com>
Date:   Thu Jun 3 10:31:54 2021 +0900

    AJAX file uploader code clean up

    Add global abort and connected clean up of function calls and element
    show/hide blocks

    Add simple progress bar for upload (in connection with percent upload)

    Move running AFUS object into the config object

    Added new config object entries for this:
    - abort: flagged true if global abort is triggered
    - running: moved from AFUS_running into config, how many uploads are
      currently running
    - current: current file_pos running (that is queue position in array)
    - current_xhr: current XHR upload object, used for abort calls

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
commit b061008ca0b496f6157b8f073d7ca14abb469ef5 ┃
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━
Author: Clemens Schwaighofer <clemens.schwaighofer@egplusww.com>
Date:   Thu May 27 11:51:47 2021 +0900

    Update AJAX file uploader to work sequential

    Rewrite flow in ajax uploader to use promsies to launch a new upload
    only if the previous upload was finished (in any way)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
commit a2ec369a8cae65e216fe402ac8b5d106e3db99af ┃
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━
Author: Clemens Schwaighofer <clemens.schwaighofer@egplusww.com>
Date:   Thu May 20 11:48:38 2021 +0900

    Updated ajax simple file uploader to allow multiple file uploads

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
commit 66878f89c82fe914031e113e780fd72e9ff09b78 ┃
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━
Author: Clemens Schwaighofer <clemens.schwaighofer@egplusww.com>
Date:   Mon May 10 09:13:25 2021 +0900

    Excel vendor sub module, ajax delay test, ajax file upload fix, others

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
commit e4efbbfdf843d8b2e53e4d3c873799b839875721 ┃
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━
Author: Clemens Schwaighofer <clemens.schwaighofer@egplusww.com>
Date:   Fri Apr 9 13:44:28 2021 +0900

    ajax file upload updates, byte format test fixes, ssh2 test fixes, array append test add, nested array recursive walk test add

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
commit 88734ebaf7420a704a538f0a923ce6996b0b5237 ┃
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━
Author: Clemens Schwaighofer <clemens.schwaighofer@egplusww.com>
Date:   Mon Jan 25 17:15:14 2021 +0900

    Add ajax uploader on error external function call

    Like post success uploaded, this function is called on any "non success"
    return falue.

    Passes on the full returned ajax data object

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
commit 2098fe53d510c03f291eaa5c4b2aefd60c24448e ┃
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━
Author: Clemens Schwaighofer <clemens.schwaighofer@egplusww.com>
Date:   Wed Jan 13 06:29:20 2021 +0900

    Add additional parameters method parameter

    Added on init of form, when submitted before additional external form
    parameters function is called

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
commit 0c2211e2312abf368c4151dbdf54d4fa96a121dc ┃
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━
Author: Clemens Schwaighofer <clemens.schwaighofer@egplusww.com>
Date:   Tue Jan 12 10:09:42 2021 +0900

    AJAX File uploader change for external function call.

    External functions are passed into the uploader as parameters.
    With this we can have unique functions for each init

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
commit c1eb15e30df319db1d5104bc5e4ab0cd8bb7cc8c ┃
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━
Author: Clemens Schwaighofer <clemens.schwaighofer@egplusww.com>
Date:   Fri Jan 8 09:59:33 2021 +0900

    AJAX file uploader target action router value dynamic setting update, other test php files updates and additions

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
commit 429af6db892d6968ad87a3db662f3ff1a9d74270 ┃
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━
Author: Clemens Schwaighofer <clemens.schwaighofer@egplusww.com>
Date:   Thu Nov 5 11:33:30 2020 +0900

    AJAX file uploader test code

    Simple single file AJAX file uploader with backend code sample.

    Work in progress with open
    - better, simpler frontend code insert part
    - multiple file upload
    - flag auto handling zip files (or tar, etc)
    - make it not rely on Jquery at all
2021-10-12 08:55:21 +09:00

4.7 KiB
Executable File

AJAX simple file upload

Upload multiple files with progress. Has hooks for pre/post work

How to use

include ajaxFileUploadSimeple.js

How to run

init with initAjaxUploader(ConfigObject)

Where the config object can have the following settings

Config Object settiings

{String} target_file

Must be set prefix for the element for the file upload

{String} target_form

Must be set the master form in which this element sits

{Number} [max_files=1]

maximum uploadable files, if 1, multiple will be removed from input file field, if 0, no limit

{Number} [max_file_size=0]

In bytes, maximum file size. If not set unlimited. 0 is also unlimited

{Array} [allowed_extensions=[]]

Allowed file extensions. Without leading '.'. Will be added to the input file accept list

{Array} [allowed_file_types=[]]

Allowed file types in mime format. Will be added to the input file accept list

{String} [target_router='']

value of the action _POST variable, if not set or if empty use "fileUpload"

{String} [target_action='']

override the target_form action field

{Object} [form_parameters={}]

Key/Value list for additional parameters to add to the form submit. Added BEFORE fileBeforeUpload parameters

{Object} [translation={}]

Translated strings pushed into the AFUS_strings object

{Boolean} [auto_submit=false]

if we override the submit button and directly upload

{Function} [fileChange='']

Function run on change of -file element entry. Parameters are target_file, file_pos, target_router

{Function} [fileChangeAll='']

Function run on change of -file element entry after all file changes for each entry are run. Parameters are target_file, target_router

{Function} [fileRemove='']

Called when an upload file is removed from the queue before upload. Parameters are target_file, file_pos

{Functuon} [fileClear='']

called when clear button is pressed. Parameters are target_file

{Function} [fileBeforeUploadAll='']

Function called before uploads start. Parameters are target_file, target_router

{Function} [fileBeforeUpload='']

Function called before upload starts. Parameters are target_file, file_pos, target_router

{Function} [fileUploaded='']

Function called after upload has successfully finished. Parameters are target_file, file_pos, target_router, data (object returned from upload function call)

{Function} [fileUploadedAll='']

After all uploads have been done, this one will be called. Parameters are target_file, target_router

{Function} [fileUploadError='']

Function called after upload has failed. Parameters are target_file, file_pos, target_router, data (object returned from upload function call)

Method call flow

[**1**] initAjaxUploader
[1 run 2] check if browser is capable for uploader
[1 run 1-A] run config check
[1 listen 8-C] cancel upload output
[1 run 3] afusPassThroughEvent
[1 run 4] run main file uploader function attachment
[1-A] afusUploaderConfigCheck check and clean config
[**2**] afusSupportAjaxUploadWithProgress
[**3**] afusPassThroughEvent
[3 set 1] change event on input file
[3 call 3-A] file extension check
[3 call 3-B] file type check
[3 set 2] sets upload queue delete in fileChange function
[3 ext 2-1] fileRemove function
[3 ext] fileChange function
[3 ext] fileChangeAll
[3 set 3] call click submit if auto submit
[3-A] afusHasExtension
[3-B] afusHasFileType
[**4**] afusInitFullFormAjaxUpload
[4 set 1] on submit function
[4 ext] fileBeforeUploadAll function
[4 run 6] afusSendFile main file send (promise)
[4 run 5] call class for async submitter iterator
[4 on finally call 8-C] finally promise: afusFinalPostUpload
[4 on finally ext] finally promise: call fileUploadedAll external
[**5**] class afusAsyncUploader
[5-A] class constructor for init
[5-B] iterator internal loop method for processing files
[**6**] afusSendFile
[6 ext] fileBeforeUpload function
[6] main xhr uploader start
[6 set 7-A] loadstart event afusOnloadStartHandler
[6 set 7-C] progress event afusOnProgressHandler
[6 set 7-B] load event afusOnloadHandler
[6 set 7-D] readystatechange event afusOnReadyStateChangeHandler
[7-A] afusOnloadStartHandler
[7-A call 9-A] add +1 to running
[7-B] afusOnloadHandler
[7-C] afusOnProgressHandler
[7-D] afusOnReadyStateChangeHandler
[7-D call 9-B] -1 for running queue count
[7-D call 8-B] afusUploadError
[7-D call 8-A] if success afusPostUpload
[7-D ext] if error fileUploadError function
[8-A] afusPostUpload
[8-B] afusUploadError
[8-C] afusCancelUploadOutput
[8-D] afusFinalPostUpload
[8-E] afusResetInternalVariables
[9-A] afusRunningStart
[9-B] afusRunningStop
[9-C] afusRunningGet