Axios POST请求和PHP $ _FILES

I am working on an API and I have to make a POST request on a PHP server to upload files.

Currently, the php server looks if the $_FILES is empty or not

This is what my query looks like in my API:

var bodyFormData = new FormData();  
for (var file in parameters.files) {  
    bodyFormData.append('file',  fs.createReadStream('uploads/'+parameters.files[file].name));
}
//console.dir(bodyFormData);
var methodToken = response.data.methodToken;
var configUploadFiles = {
    url: '/upload/',
    method: 'post',
    baseURL: 'http://192.168.170.52',
    headers: {'Content-Type': 'multipart/form-data', 'userToken': userToken, 'methodToken': methodToken},
    data: bodyFormData
}

axios.request(configUploadFiles)
.then(response => {
    // Do somethink
})
.catch(error => {
    // Do otherthink
});

The query runs fine and here is a console.log of my FormData:

FormData {
    _overheadLength: 317,
    _valueLength: 0,
    _valuesToMeasure: 
         [ ReadStream {
             _readableState: [Object],
             readable: true,
             domain: null,
             _events: [Object],
             _eventsCount: 3,
             _maxListeners: undefined,
             path: 'uploads/1_RFM_Achats.txt',
             fd: null,
             flags: 'r',
             mode: 438,
             start: 0,
             end: Infinity,
             autoClose: true,
             pos: 0,
             bytesRead: 0,
             emit: [Function] },
         ReadStream {
             _readableState: [Object],
             readable: true,
             domain: null,
             _events: [Object],
             _eventsCount: 3,
             _maxListeners: undefined,
             path: 'uploads/1_RFM_Clients.txt',
             fd: null,
             flags: 'r',
             mode: 438,
             start: 0,
             end: Infinity,
             autoClose: true,
             pos: 0,
             bytesRead: 0,
             emit: [Function] } ],
      writable: false,
      readable: true,
      dataSize: 0,
      maxDataSize: 2097152,
      pauseStreams: true,
      _released: false,
      _streams: 
          [ '----------------------------246027426731056834535848
Content-Disposition: form-data; name="file"; filename="1_RFM_Achats.txt"
Content-Type: text/plain

',
            DelayedStream {
                source: [Object],
                dataSize: 0,
                maxDataSize: Infinity,
                pauseStream: true,
                _maxDataSizeExceeded: false,
                _released: false,
                _bufferedEvents: [Array],
                _events: [Object],
                _eventsCount: 1 },
            [Function: bound ],
             '----------------------------246027426731056834535848
Content-Disposition: form-data; name="file"; filename="1_RFM_Clients.txt"
Content-Type: text/plain

',
             DelayedStream {
                 source: [Object],
                 dataSize: 0,
                 maxDataSize: Infinity,
                 pauseStream: true,
                 _maxDataSizeExceeded: false,
                 _released: false,
                 _bufferedEvents: [Array],
                 _events: [Object],
                 _eventsCount: 1 },
             [Function: bound ] ],
             _currentStream: null,
             _boundary: '--------------------------246027426731056834535848' }

The problem is that in the processing of POST, on the server in PHP, the variable $_FILES is empty

When i error_log $_FILES : Array ( )

and I must absolutely go through this variable because there would be too much change to make

doujing6053
doujing6053 您需要提供一个可重复性最小的示例。由于代码是文本:将其作为文本提供,而不是图片,并且不要遗漏重要且相关的信息,例如bodyFormData的值。
接近 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问