I am trying to upload a image as Avatar photo to the server through the Web-API.
Anyone can explain how to insert the image URL into the data by current user id has token?
I have already done $.getJSON (url,...
I can read and append them wherever I wanted.
I have something like this:
user_id=1
/api/images/upload_form/avatar
/api/users/update_user_info
1. How can I attach the image file and post it through Web-API with jQuery?
2. And How can I re-upload(update) the file?
$(document).ready(function (e) {
$('#upload').on('click', function () {
var file_data = $('#file').prop('files')[0];
var form_data = new FormData();
form_data.append('file', file_data);
$.ajax({
url: 'https://myurl/api/images/upload_form/avatar', // point to server-side controller method
dataType: 'text', // what to expect back from the server
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'post',
success: function (response) {
$('#msg').html(response); // display success response from the server
},
error: function (response) {
$('#msg').html(response); // display error response from the server
}
});
});
});
user_id=1 << I need to add this key and value to the post url, but how?
Any help will be appreciate.
Thanks