我正在尝试使用jquery将图像上传到我的服务器。我需要将图像,文件名和文件URL发送到后端。因为我在“数据”中添加了这三个字段(参考代码)。我这样做(下面的代码),但我在控制台中收到错误,说“不支持的媒体文件”415.我该如何解决?
posterFile = e.target.files;
selectedPoster = posterFile[0];
uploadPoster() {
var blobPosterFile = selectedPoster;
console.log("U called me?")
var formData = new FormData();
formData.append("fileToUpload", blobPosterFile);
var that = this;
let token;
var settings = {
"async": true,
"crossDomain": true,
"url": "https://www.backend.example.name.com/api/v1/videos/",
"method": "POST",
processData: false,
contentType: false,
"credentials": 'include',
"headers": {
Authorization: "Token " + that.props.token_Reducer.token
},
"data": {
"Title": selectedFile.name,
"File": videoURL,
"Poster": formData
},
success:( response, textStatus, jQxhr )=> {
console.log("poster uploaded")
}
}
$.ajax(settings).done((response) => {
});
}
我收到错误消息“不支持的媒体类型”415