upload file axios
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'
}
})
3.8
5
uploadFile: function (event) {
const file = event.target.files[0]
axios.post('upload_file', file, {
headers: {
'Content-Type': file.type
}
})
}
Thank you!
5
0
3.7
10
let fileData = new FormData();
fileData.append("FileKey", myFile);
let config = { headers: {
'Content-Type': 'multipart/form-data'
}}
let url = '/fileUp';
axios.post(url, fileData,config)
.then(function(response){
})
.catch(function(error){
});
Thank you!
10
0
3.5
6
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;
}
});
}
};
Thank you!
6
0
4.29
7
Add the file to a formData object, and set the Content-Type header to multipart/form-data.
var formData = new FormData();
var imagefile = document.querySelector('#file');
formData.append("image", imagefile.files[0]);
axios.post('upload_file', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
Thank you!
7
0
Are there any code examples left?
New code examples in category Javascript
-
Javascript 2023-04-21 22:52:36
-
Javascript 2022-03-27 22:25:20 javascript download string as file
-
Javascript 2022-03-27 21:40:22 sort numbers in array javascript
-
Javascript 2022-03-27 21:20:04 compare two arrays and return the difference javascript
-
Javascript 2022-03-27 21:15:02 javascript regex french phone number
-
Javascript 2022-03-27 21:05:03 cypress custom error message
-
Javascript 2022-03-27 21:00:05 create element javascript with id
-
Javascript 2022-03-27 20:40:57 feather icons react
-
Javascript 2022-03-27 20:20:01 how to make graphql request in axios
-
Javascript 2022-03-27 20:15:07 bootstrap validator password and confirm password