Mono file uploader module.
The most important parameters are set in the module upload operation params
array.
uploadDir
: path to the directory where the file will be uploaded (required)dsUpload
: datasource (required)dsTemporarUpload
: temporar upload datasource (required iftemporarUpload: true
in uploader template configuration)emitArgument
: sets the parameter that will be emited by module infileUploaded
event. It can take the following values:id
,path
,object
or an object:{"type": "custom", "value": "docKey"}
(upload
operation)uploadFileEvent
: name of custom handler that gets called before the uploaded object gets inserted in the db (upload
operation)customUpload
: name of custom handler that gets called in order to construct a custom upload path for the uploaded file (upload
operation)customPathHandler
: name of custom handler that gets called in order to construct a custom path to a file that needs to be downloaded (download
operation)
The file-uploader module can also receive an optional template object with a template configuration (see setTemplate
event bellow). In this case for each setTemplate
call, the module will render all configured uploaders
(see template configuration bellow) for the given template in the specified container
based on user permissions.
The most important parameters are set in the uploader
object found in the template options
configuration
uploaders
: object containing all distinct uploader configurations (a template can have multiple uploaders with diffrent configurations and permissions (upload, download, remove) all renderd by the same module instance (required)[uploaderName]
the name of the uploader instance (required)container
the selector used to find the container where the uploader will be rendereduploadDir
path to the directory where the file will be uploaded (this path will be appended to theuploadDir
value found in the moduleparams
array)customUpload
name of custom handler that gets called in order to construct a custom upload path for the uploaded file (upload
operation)uploadFileEvent
name of custom handler that gets called before the uploaded object gets inserted in the db (upload
operation)temporarUpload
document will be uploaded to a temporar collection (true/false)access
permissions string for the module operations (upload, download, remove), can be set dynamically for each user in thecrud_access.js
file ("u" - if user has uplaod permission, "d" - download permission, "r" - remove permission)customPathHandler
name of custom handler that gets called in order to construct a custom path to a file that needs to be downloaded (download
operation)customPermissions
name of custom handler that returns custom permissions for the upload operations
html
the path to the html files/file for the upload controlscontrols
selector configurations for the upload controls (select
,upload
,fileName
)waitForEvent
the uploader will listen for aenableRendering
event before rendering the configured uploaders
"uploader": {
"module": "github/jillix/file-uploader/[VERSION]",
"config": {
"html": "/path/to/html/file.html",
"options": {
"acceptTypes": ["txt", "and", "other", "file", "extensions"]
},
"binds": [BIND_OBJECTS],
"listen": {EVENT_OBJECTS}
},
"roles": [MONO_ROLES],
"operations": {
"upload": {
"roles": [MONO_ROLES],
"params": [
{
"dsUpload": "temporarDS",
"emitArgument": "path",
"acceptTypes": ["txt", "and", "other", "file", "extensions"],
"uploadDir": "path/to/upload/dir",
"uploadFileEvent": "uploadedFileToImport",
"customUpload": "getUploadCustomPath"
}
]
},
"download": {
"roles": [MONO_ROLES],
"params": [
{
"dsUpload": "temporarDS",
"uploadDir": "path/to/upload/dir",
"customPathHandler": "getDocCustomPath"
}
]
},
"remove": {
"roles": [MONO_ROLES],
"params": [
{
"dsUpload": "temporarDS",
"uploadDir": "path/to/upload/dir",
"removeFileEvent": "exampleHandler"
}
]
},
"getDocuments": {
"roles": [MONO_ROLES],
"params": [
{
"dsUpload": "temporarDS"
}
]
},
"getUploadPermissions": {
"roles": [MONO_ROLES],
"params": [{}]
}
}
},
Where temporarDS
is defined into datasources
key from application descriptor:
{
...
"datasources": {
"temporarDS": {
"type": "mongo",
"db": "databaseName",
"collection": "temp"
}
},
...
}
uploader: {
uploaders: {
[UPLOADER_NAME]: {
container: [CSS_SELECTOR],
uploadDir: "path/to/upload/dir",
customUpload: "handlerName",
uploadFileEvent: "handlerName",
temporarUpload: true, // default false
access: 'urd',
customPermissions: "handlerName",
customPathHandler: "handlerName"
}
},
html: "path/to/htmlFile.html", // can be i18n object
controls: {
select: ".btn-upload-select",
upload: ".btn-upload-start",
fileName: ".file-name"
},
waitForEvent: true // default false
}
The module emits the following events:
Event name | Description | Parameters |
---|---|---|
fileUploaded |
It is emited when the file is uploaded | uploaded file id , path or the entire object. This can be set in the module upload operation parameters. |
uploadFailed |
It is emited when the upload process encountered an error and failed | The error encountered. This parameter can be missing. |
itemRemoved |
It is emited when the file is successfully removed | none |
uploadersRendered |
It is emited when the template configured uploaders finish rendering | none |
The module listens for the following events:
Event name | Description | Parameters |
---|---|---|
setTemplate |
Sets the template and renders uploaders based on the configuration found inside the template | The full template object or the template `_id` as string. |
enableRendering |
Starts the uploaders rendering if the `waitForEvent` is true | none |
setData |
Data sent will be appended to the upload form | `data` object |
reset |
For template uploaders only. Resets the uploader controls | none |
rebuildUi |
For template uploaders only. The uploader will ask again for the upload permissions and rebuild the uploaders based on the permissions that might have changed | none |
removeItem |
Removes the specified item from the DB and FS | An object containing the `itemId` and `uploader` (the name of the uploader instance configured in the `uploaders` field) if the document was uploaded using a template uploader |
getDocuments |
For template uploaders only. Returns the documents for a specified `uploader` and `template` based on the user permissions. Also returns `removeForbidden: true` if the user cannot remove the requested documents | An object containing `uploader` name and `template` object or id as string |
- Added "template uploaders" functionality
- transferred the module to the new jxMono organization
- updated Bind to
v0.4.0
, Events tov0.4.0
- Clear the existing hidden inputs when
setData
is called
removeItem
client function can receive object as parameter
- Added
removeFileEvent
remove operation event
- Updated to Bind
v0.3.2
- catching server side errors during upload
- added
uploadFile
event - fixed IE upload problem (IFRAME does not understand application/json content type)
- piping downloaded files
- checking if file exists for download
- Updated to Bind
v0.3.1
- Updated deps
- Added custom handler support for the file path in the download operation
- Removed the
Content-Disposition
attachment
directive for the download operation - Removed the
text/csv
Content-Type
from the download operation
- Moved the
fileUploaded
event emit higher in the code
- Check the file size when uploading a file
- Update to Events v0.1.11
acceptTypes
options (both client and server) if not present, allows any file type uploads- add new features and fixed here
- Update to Events v0.1.10
- Update to Bind v0.2.2
- Update to Events v0.1.8
acceptTypes
configuration and param fields- Update to Bind v0.2.1
- Update to Events v0.1.7
- Don't emit
fileUploaded
if no file was selected in the file input
- initial version