I'm trying to post an image using axios
I was earlier using post form method
<div>
<form method="post" action="/imgUpload" enctype="multipart/form-data">
<input type="file" name="file" autocomplete="off" required>
<input type="submit" value="Submit">
</form>
</div>
@app.route('/imgUpload', methods=['POST'])
def upload_image():
file = request.files['file']
filename = secure_filename(file.filename)
file.save(os.path.join('/home/user/images', filename))
return render_template('test.html')
How to replicate the same process using axios. Should I add a function for submit and send the image data?
sample axios function:
function getName(name) {
var user_name = name;
axios({
method: "get",
url: "/send_name",
params: {
user_name
}
}).then(function (response) {
response_data = response.data["img_data"];
});
};
What changes should I make to form and the axios function to post an image?