Skip to content

Instantly share code, notes, and snippets.

@rquast
Created May 19, 2017 21:56
Show Gist options
  • Save rquast/16debed7dec125ab6b9e76ede3100036 to your computer and use it in GitHub Desktop.
Save rquast/16debed7dec125ab6b9e76ede3100036 to your computer and use it in GitHub Desktop.
attached() {
this.fu = new qq.FineUploaderBasic({
// button: document.getElementById('uploadButton'),
request: {
endpoint: '/api/upload',
inputName: 'qqfile'
},
validation: {
// acceptFiles: ['image/jpeg', 'image/jpg', 'image/png', 'application/pdf'],
// allowedExtensions: ['jpeg', 'jpg', 'pdf', 'png'],
// itemLimit: 1,
sizeLimit: 8500000000
},
chunking: {
enabled: true,
concurrent: {
enabled: true
},
success: {
endpoint: '/api/uploaddone'
}
},
paramsInBody: true,
callbacks: {
onSubmit: (id, fileName) => {
this.stats = 'Uploading';
this.uploadSpeeds = [];
if (this.$parent !== undefined && this.$parent.showChatInput) {
this.fu.setCustomHeaders(CavyConnect.headers({}));
this.fu.setParams(this.getParams());
} else {
this.logError('Start or select a conversation before sending files.');
return false;
}
},
onUpload: (id, fileName) => {
this.completed = 0;
this.showStatus = true;
},
onProgress: (id, name, uploadedBytes, totalBytes) => {
this.completed = Math.ceil(uploadedBytes / totalBytes * 100);
this.updateSpeedText(uploadedBytes, totalBytes);
},
onComplete: (id, name, responseJSON, xhr) => {
this.showStatus = false;
if (!responseJSON.success) {
this.logError(responseJSON.error);
}
},
onError: (id, name, errorReason, xhr) => {
this.showStatus = false;
this.logError(errorReason);
},
onCancel: (id, name) => {
this.showStatus = false;
this.logInfo('Upload Cancelled');
},
onAutoRetry: (id, name, attemptNumber) => {
this.logInfo('Retrying Upload');
}
},
debug: false
});
this.uploadFileForm = document.createElement('form');
this.uploadFileEl = document.createElement('input');
this.uploadFileEl.type = 'file';
this.uploadFileForm.appendChild(this.uploadFileEl);
this.uploadFileForm.addEventListener('change', this.changeFn, false);
this.initFileDrop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment