Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery Ajax文件上传rest返回415_Jquery_Ajax_Multipartform Data - Fatal编程技术网

Jquery Ajax文件上传rest返回415

Jquery Ajax文件上传rest返回415,jquery,ajax,multipartform-data,Jquery,Ajax,Multipartform Data,我创建了用于文件上载的简单HTML表单: <form method="post" enctype="multipart/form-data" action="#" id="upload-file"> <input id="file" class="browse-files-button" value="Browse" type="file" name="files"></input> </form> 在结果中,我接收到响应415,该

我创建了用于文件上载的简单HTML表单:

<form method="post" enctype="multipart/form-data" action="#" id="upload-file"> 
      <input id="file" class="browse-files-button" value="Browse" type="file" name="files"></input>
</form>

在结果中,我接收到响应415,该响应指示415不支持的媒体类型。

问题是服务器希望接收名为“file”的文件参数,但我作为“files”发送


415错误通常意味着您正在上载的文件类型不是API想要的,或者是希望收到的文件类型。检查API文档。
var data = new FormData(AJS.$('#upload-file')[0]);
 AJS.$.ajax({
        type: "POST",
        url: getAttachmentUrl(),
        data: file,
        dataType: "json",
        cache: false,
        processData: false,
        contentType: false,
        headers: {
        "X-Atlassian-Token": "nocheck"
        },
        error : function() {
            console.log("Error while uploading file!");
        },
        success : function(result){
            console.log("File successfully uploaded!");
        }
    });
<form method="post" enctype="multipart/form-data" action="#" id="upload-file"> 
      <input id="file" class="browse-files-button" value="Browse" type="file" name="file"></input>
</form>