Message from JavaScript discussions
November 2018
— 🖐🏼
I try to upload a file to a server using axios by the post method, I use showOpenDialog to search the file but at the time of loading it I read that with fs I could do it but nothing loads only the address of the directory where the file is located and I do not get send it to the server
— Create a readstream and send it
— Si quieres podemos hablar en español xd
— Sí, por favor 😅
—
fs.ReadStream(filename[0], (err, arch) => {
if(err) {
console.log('¡Error!')
throw err
}
const form = new FormData()
form.append('file', arch)
r = axios.post(url + '/upFile', form, {
headers: {
'Content-Type': 'multipart/form-data',
}
})
})
— Es lo que estoy usando para subir el archivo, pero no me ha funcionado muy bien
— Me da ese error al intentar abrir un archivo con ReadStream
— Es que el segundo parametro es para las opciones
— Tu por un lado creas el readstream y lo dejas ahí
— Y por otro haces lo que sea
— Var a = fs.createReadStream(path[, options])