I need jquery ajax expert who can upload image and video. please see the job description carefully.
This code works well without Image or video file.
but I want this code works with Image or video file.
please use these sample parameters.
now there isn't image or video file appending to formdata.
you should add them.
this is the code:
var fd = new FormData();
var country_id = 233;
if(_lang === 'cn') {
country_id = 45;
}
[login to view URL]("country_id", country_id);
[login to view URL]("latitude", lat);
[login to view URL]("longitude", lng);
[login to view URL]("title", 'Test title');
[login to view URL]("category_id", 55);
[login to view URL]("price", 100);
var description = [login to view URL];
[login to view URL]("description", description);
[login to view URL]("hashtag", '#lucky');
/**************************/
[login to view URL]('images[], imagefiles),
[login to view URL]('video', videofile)
/*************************/
var url = '[login to view URL]';
$.ajax({
url: url,
type: 'POST',
headers: {
token: '8Pk1Jc3s5yxfsyX84tjx',
},
encType: 'multipart/form-data',
processData:false,
contentType:false,
cache: false,
data: fd ,
crossDomain: true,
success: function(response) {
[login to view URL](response);
},
error: function(err) {
[login to view URL](err);
}
});
if you get the result like following with file, your code works well.
but I can't change the third party API code([login to view URL]').
{"result":"SUCCESS","response":"{\"post\":{\"id\":14514,\"title\":\"Test Title\",\"open_time\":null,\"price\":111.0,\"short_description\":\"asdfasdf\\n\",\"description\":\"\\u003cp\\u003easdfasdf\\u003c\/p\\u003e\\n\",\"video\":{\"url\":null,\"thumb\":{\"url\":null}},\"feature\":false,\"view\":1,\"is_liked\":null,\"is_favorited\":null,\"is_sold\":false,\"like_count\":0,\"latitude\":\"40.748977953715126\",\"longitude\":\"-74.34634072753909\",\"custom_field\":null,\"qrcode\":{\"url\":\"https:\/\/[login to view URL]\/uploads\/post\/qrcode\/14514\/[login to view URL]\",\"thumb\":{\"url\":\"https:\/\/[login to view URL]\/uploads\/post\/qrcode\/14514\/[login to view URL]\"},\"small\":{\"url\":\"https:\/\/[login to view URL]\/uploads\/post\/qrcode\/14514\/[login to view URL]\"}},\"is_sell\":false,\"post_video\":{\"video\":{\"url\":null,\"thumb\":{\"url\":null}},\"created_at\":\"2018-10-24T14:05:11.000+08:00\"},\"created_at\":\"2018-10-24T14:05:11.000+08:00\",\"image_header\":null,\"post_images\":[],\"user\":{\"id\":2122,\"user_name\":\"88905864\",\"full_name\":\"SSK Test\",\"email\":\"[login to view URL]@[login to view URL]\",\"phone_number\":null,\"overall_rating\":0,\"rated\":0,\"rating\":null,\"is_followed\":null,\"avatar\":{\"url\":null,\"thumb\":{\"url\":null},\"small\":{\"url\":null}}},\"category\":{\"id\":55,\"title\":\"SkinCare\",\"enable_shopping_cart\":true,\"category_id\":4,\"image\":{\"url\":\"https:\/\/[login to view URL]\/uploads\/category\/image\/55\/[login to view URL]\",\"thumb\":{\"url\":\"https:\/\/[login to view URL]\/uploads\/category\/image\/55\/[login to view URL]\"},\"small\":{\"url\":\"https:\/\/[login to view URL]\/uploads\/category\/image\/55\/[login to view URL]\"}}}}}"}
this code will be used in reactjs project.
you should implement this on js file.