I want to create an API to send a photo or video to https://partner.path.com/1/moment/photo(recorded as A)
It can be done successfully by curl as the following:
curl -H 'Authorization: Bearer <ACCESS_TOKEN>'
-F "image=@F:photo.jpg"
-F 'data={"caption": "I like cheese!"}'
A
However,it is failed(400 BAD_REQUEST) when sending the request by Ajax as the following:
$.ajax({
type : "POST",
url : "A",
async : false,
data : "{"image":"@F:photo.jpg", "caption":"I like the picture", "private":true}",
dataType : 'json',
contentType : "application/json",
crossDomain : true,
beforeSend : function(xhr) {
xhr.setRequestHeader("Authorization", "Bearer 5f323a1c21a89cde270ffe78b3835d8a4bdd67c0");
},
success : function(res, textStatus) {
console.log(res);
}
});
I think the problem maybe exist on the parameters(particularly the data parameter) when making ajax call. What is the correct format of the data parameter?