Hey guys!
I am trying to use uppy in a node(express) project and I am having a bad time trying to use it.
Here is my Companion config:
const optionsCompanion = {
providerOptions: {
google: {
key: process.env.GOOGLE_CLIENT_ID,
secret: process.env.GOOGLE_SECRET_KEY_CLIENT,
},
dropbox: {
key: process.env.DROPBOX_KEY,
secret: process.env.DROPBOX_SECRET_KEY,
},
},
server: {
host: "localhost:3020",
protocol: "http",
},
filePath: "./public/upload",
secret: "xxxx", //same session secret
};
app.use(companion.app(optionsCompanion));
var serverUppy = app.listen(3020);
companion.socket(serverUppy, optionsCompanion);
And here is my uppy client config:
var uppy = Uppy.Core({
restrictions: {
maxFileSize: 52428800,
minNumberOfFiles: 1,
allowedFileTypes: arrayExtensoes(),
},
meta: {
TamanhoMaxPorDocumento: document.querySelector("#TamanhoMaxPorDocumento")
.value,
MaxDocsPorEnvelope: document.querySelector("#MaxDocsPorEnvelope").value,
latitude: document.querySelector('[name="latitude"]').value,
longitude: document.querySelector('[name="longitude"]').value,
browser: document.querySelector('[name="browser"]').value,
so: document.querySelector('[name="so"]').value,
ip: document.querySelector('[name="ip"]').value,
idpasta: document.querySelector('[name="idpasta"]').value,
repositorio: document.querySelector('[name="repositorio"]').value,
gerarTags: document.querySelector('[name="gerarTags"]').value,
descricao: document.querySelector('[name="descricao"]').value,
nomerepositorio: document.querySelector('[name="nomerepositorio"]').value,
},
});
uppy
.use(Uppy.Dashboard, {
target: "body",
trigger: "#add-documents",
closeModalOnClickOutside: true,
closeAfterFinish: true,
showProgressDetails: true,
height: 300,
locale: Uppy.locales.pt_BR,
proudlyDisplayPoweredByUppy: false,
showRemoveButtonAfterComplete: false,
browserBackButtonClose: true,
})
.use(Uppy.GoogleDrive, {
target: Uppy.Dashboard,
companionUrl: "localhost:3020",
companionHeaders: {
"Acess-Control-Allow-Origin": " <em>",
"Access-Control-Allow-Methods": "OPTIONS, GET, POST, PATCH, PUT",
"Access-Control-Allow-Headers":
"Origin, X-Requested-With, Content-Type, Accept, Authorization, Extra-Data",
},
})
.use(Uppy.Dropbox, {
target: Uppy.Dashboard,
companionUrl: "localhost:3020",
companionHeaders: {
"Acess-Control-Allow-Origin": "</em> ",
"Access-Control-Allow-Methods": "OPTIONS, GET, POST, PATCH, PUT",
"Access-Control-Allow-Headers":
"Origin, X-Requested-With, Content-Type, Accept, Authorization, Extra-Data",
},
})
.use(Uppy.XHRUpload, {
method: "post",
endpoint: "localhost:3000/envelopes",
formData: true,
fieldName: "files",
headers: {
"Acess-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "OPTIONS, GET, POST, PATCH, PUT",
"Access-Control-Allow-Headers":
"Origin, X-Requested-With, Content-Type, Accept, Authorization, Extra-Data",
},
});
I am trying to send some input hidden (you can see those inputs in meta) with XHRUpload, but I am having a lot of troubles. I can’t find the inputs values in my controller when debugging my request variable.
The other problems was solved with this line:
app.use(bodyParser.json({ type: ['application/json', 'text/plain'] }))
app.use(cors())
app.options('*', cors())
But I am still having some troubles with cors policy.
The upload seems to work as you can see here in companion log:
companion: 2020-08-05T19:30:12.418Z [debug] 009bbf7a uploader.upload.progress 1102331 1102331 100.00%
But after i got this error: companion: 2020-08-05T19:30:12.428Z [error] upload.multipart.error upload failed with status: 400
And in console i got these errors:
Access to fetch at localhost/drive/list/root from origin localhost:3000 has been blocked by CORS policy: Method OPTIONS is not allowed by Access-Control-Allow-Methods in preflight response.
RequestClient.js:1 OPTIONS localhost:3020/drive/list/root net::ERR_FAILED.
Access to fetch at localhost:3020/drive/get/1zz-IOdBjEZyvX2_Z_rd6sx1YPeBZ7f-a' from origin localhost:3000 has been blocked by CORS policy: Method OPTIONS is not allowed by Access-Control-Allow-Methods in preflight response.
OPTIONS localhost:3020/drive/get/1zz-IOdBjEZyvX2_Z_rd6sx1YPeBZ7f-a net::ERR_FAILED.
[Uppy] [16:18:37] Failed to upload Assinatura Tomás.jpg Bad Request.
I was trying using Form too, but when the input hidden with file data was attached in my the data value of file was a blank object, and when i submit the form i was not able to save the file in database.
I also would like to know how to send an array of files to my endpoint, because my users should be able to select multiples files. At the moment when i select multiple files only the last one is sent to my controller.
I would love any help.
Thanks
Tomás Loureiro Gomes