uploading file with axios code example

Example 1: axios file upload

const formData = new FormData();
const imagefile = document.querySelector('#file');
formData.append("image", imagefile.files[0]);
axios.post('upload_file', formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
})

Example 2: upload a file to s3 axios

var aws = require('aws-sdk');

aws.config.update({
    accessKeyId: AWS_ACCESS_KEY
    secretAccessKey: AWS_SECRET_KEY
});

exports = module.exports = {
    sign: function(filename, filetype) {
        var s3 = new aws.S3();

        var params = {
            Bucket: SOME_BUCKET,
            Key: filename,
            Expires: 60,
            ContentType: filetype
        };

        s3.getSignedUrl(‘putObject’, params, function(err, data) {
            if (err) {
                console.log(err);
                return err;
            } else {
                return data;
            }
        });
    }
};