1const formData = new FormData();
2const imagefile = document.querySelector('#file');
3formData.append("image", imagefile.files[0]);
4axios.post('upload_file', formData, {
5 headers: {
6 'Content-Type': 'multipart/form-data'
7 }
8})
1Add the file to a formData object, and set the Content-Type header to multipart/form-data.
2
3var formData = new FormData();
4var imagefile = document.querySelector('#file');
5formData.append("image", imagefile.files[0]);
6axios.post('upload_file', formData, {
7 headers: {
8 'Content-Type': 'multipart/form-data'
9 }
10})
1var aws = require('aws-sdk');
2
3aws.config.update({
4 accessKeyId: AWS_ACCESS_KEY
5 secretAccessKey: AWS_SECRET_KEY
6});
7
8exports = module.exports = {
9 sign: function(filename, filetype) {
10 var s3 = new aws.S3();
11
12 var params = {
13 Bucket: SOME_BUCKET,
14 Key: filename,
15 Expires: 60,
16 ContentType: filetype
17 };
18
19 s3.getSignedUrl(‘putObject’, params, function(err, data) {
20 if (err) {
21 console.log(err);
22 return err;
23 } else {
24 return data;
25 }
26 });
27 }
28};
1 let fileData = new FormData();
2 fileData.append("FileKey", myFile);
3
4 let config = { headers: {
5 'Content-Type': 'multipart/form-data'
6 }}
7 let url = '/fileUp';
8
9 axios.post(url, fileData,config)
10 .then(function(response){
11
12 })
13 .catch(function(error){
14
15 });
16
1uploadFile: function (event) {
2 const file = event.target.files[0]
3 axios.post('upload_file', file, {
4 headers: {
5 'Content-Type': file.type
6 }
7 })
8}
9