使用 Angular ng file upload 上传文件时出错

Error while uploading a file with Angular ng file upload

我在将文件加载到我的服务器时遇到问题。我遵循演示中提供的结构:

file.upload = this.Upload.upload({
          url: "/api/license/upload",
          method: "POST",
                 data: {
                     name:file.name
                 },
                 file: file
          }).then(function (resp:any) {
               console.log('Success ' + resp.config.data.file.name + 'uploaded. Response: ' + resp.data);
            }, function (resp:any) {
                 console.log('Error status: ' + resp.status);
            }, function (evt:any) {
                var progressPercentage = parseInt(evt.loaded / evt.total);
                 console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
          });
 }

但是,当我尝试上传文件时,在服务器的响应中我得到 200(这没问题),但随后应用程序崩溃并显示以下内容:

SyntaxError: Unexpected token Y
    at Object.parse (native)
    at vc (http://localhost:4000/dist/vendor.min.js:20:480)
    at Zb (http://localhost:4000/dist/vendor.min.js:87:229)
    at http://localhost:4000/dist/vendor.min.js:88:143
    at m (http://localhost:4000/dist/vendor.min.js:12:322)
    at dd (http://localhost:4000/dist/vendor.min.js:88:125)
    at d (http://localhost:4000/dist/vendor.min.js:89:380)
    at http://localhost:4000/dist/vendor.min.js:124:113
    at n.$eval (http://localhost:4000/dist/vendor.min.js:138:221)
    at n.$digest (http://localhost:4000/dist/vendor.min.js:135:233)

对可能出现的问题有什么想法吗?

好的,我发现了问题所在:服务器的响应是字符串形式,而不是 JSON。