使用角度素数ng问题导入文件



我正在研究Angular中的文件导入功能。从邮递员那里,我能够正确地发出请求,但从 Angular 我得到了一个错误。请纠正我做错了什么。

角度代码(素数吴(

<p-fileUpload mode="basic" name="demo[]" url="https://gateway.xxx.intra/file"  maxFileSize="1000000" (onUpload)="onBasicUpload($event)" auto="true">

来自服务器的响应

SyntaxError: Unexpected token - in JSON at position 0
    at JSON.parse (<anonymous>)
    at createStrictSyntaxError (/usr/src/gateway/node_modules/body-parser/lib/types/json.js:158:10)
    at parse (/usr/src/gateway/node_modules/body-parser/lib/types/json.js:83:15)
    at /usr/src/gateway/node_modules/body-parser/lib/read.js:121:18
    at invokeCallback (/usr/src/gateway/node_modules/raw-body/index.js:224:16)
    at done (/usr/src/gateway/node_modules/raw-body/index.js:213:7)
    at IncomingMessage.onEnd (/usr/src/gateway/node_modules/raw-body/index.js:273:7)
    at IncomingMessage.emit (events.js:160:13)
    at endReadableNT (_stream_readable.js:1101:12)
    at process._tickCallback (internal/process/next_tick.js:152:19)

邮递员标题

curl -X POST 
  https://gateway.xxx.intra/file 
  -H 'Postman-Token: xxxx3d14-dfee-4c6b-85e1-5592c2e0f9e2' 
  -H 'cache-control: no-cache' 
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' 
  -F 'send_files[]=@C:UsersxxxDocumentsimport_template.xlsx'

浏览器请求标头是

------WebKitFormBoundaryjZxBpNsIzAmLi5Sy
Content-Disposition: form-data; name="demo[]"; filename="import_template.xlsx"
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

------WebKitFormBoundaryjZxBpNsIzAmLi5Sy--

当您向服务器发出请求并将响应解析为 JSON 时,会发生这种情况,但它不是 JSON。

最新更新