meteor-autoform-file
meteor-autoform-file copied to clipboard
Adding hooks
I have a suggestion:
I am still using this and I came to some limits I'd like to solve with some hooks:
picture: {
type: String,
autoform: {
afFieldInput: {
type: 'fileUpload',
collection: 'Images',
hooks: {
onProgress: () => {}, // while in progress
onComplete: () => {}, // progress === 100%
onError: err => {}, // there was an upload error
onRemove: fileId => {}, // user wants to delete the uploaded file
onRemoved: () => {}, // the file has been removed
}
}
}
}
The reasons are simple:
- disable form submit/cancel until file has been uploaded
- let users remove their uploaded file by using a custom Meteor method (because the default remove is disabled)
- custom way of communicating upload errors to the user
Even easier would be to just pass the Upload context from insert:
picture: {
type: String,
autoform: {
afFieldInput: {
type: 'fileUpload',
collection: 'Images',
hooks: {
onUpload: (file, uploadCtx) => {}, // hook into upload ctx
onRemove: fileId => {}, // user wants to delete the uploaded file
}
}
}
}