Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A js file to use Uppy file uploads with laravel-mix
const Uppy = require('@uppy/core');
const XHRUpload = require('@uppy/xhr-upload');
const Dashboard = require('@uppy/dashboard');
const PortuguesBR = require('@uppy/locales/lib/pt_BR');
/**
* Cria uma instância do plugin Uppy
* @param {String|Object} options objeto com algumas opções do plugin
*/
window.uploadFiles = (options) => {
const defaults = () => {
return {
width: null,
height: null,
url: null,
target: null,
meta: {},
headers: {},
fieldName: 'file',
metaFields: null,
restrictions: {
maxFileSize: 2000,
},
formData: false,
success: function (result) {
console.log(`upload completado com sucesso: ${result}`);
}
}
};
options = Object.assign(defaults, options);
Uppy({
meta: options.meta,
})
.use(Dashboard, {
width: options.width,
height: options.height,
target: options.target,
inline: true,
showProgressDetails: true,
restrictions: options.restrictions,
locale: PortuguesBR
})
.use(XHRUpload, {
endpoint: options.url,
headers: options.headers,
fieldName: options.fieldName,
metaFields: options.metaFields,
formData: options.formData
})
.on('complete', options.success);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment