material-ui-dropzone icon indicating copy to clipboard operation
material-ui-dropzone copied to clipboard

I can't able to upload files using axios.

Open saileshkush95 opened this issue 3 years ago • 1 comments

I'm using axios and dialog dropzone, everything works fine but I cant able to upload files to the server.

saileshkush95 avatar May 06 '21 10:05 saileshkush95

You can crearte formData and for files you would be use .map and send information for example for many files

const bodyFormData = new FormData(); files.map(file =>bodyFormData.append("file", file))

and the axios I create a function

const response = await fethWithTokenMultiData('projects/create',bodyFormData)

and function use 'multipart/form-data'

export const fethWithTokenMultiData = async(endpoint,data=null,fileType='multipart/form-data') =>{
    const url = 'example url';
    const token = localStorage.getItem('token') || '';
    const config = {
        headers: {
            'Authorization':token,
            'Content-Type': fileType
        }
    }

    try {
        const response = await axios.post(url,data,config)
        return response
    } catch (error) {
        console.log(error);
    }
}

santilp95 avatar Jul 01 '21 20:07 santilp95