Axios POST请求和PHP $ _FILES

loading...


0

我正在研究API,我必须在 PHP server 上发送POST请求才能上传文件 .

目前, php server 查看 $_FILES 是否为空

这是我的查询在我的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
});

查询运行正常,这是 FormDataconsole.log

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\r\nContent-Disposition: form-data; name="file"; filename="1_RFM_Achats.txt"\r\nContent-Type: text/plain\r\n\r\n',
            DelayedStream {
                source: [Object],
                dataSize: 0,
                maxDataSize: Infinity,
                pauseStream: true,
                _maxDataSizeExceeded: false,
                _released: false,
                _bufferedEvents: [Array],
                _events: [Object],
                _eventsCount: 1 },
            [Function: bound ],
             '----------------------------246027426731056834535848\r\nContent-Disposition: form-data; name="file"; filename="1_RFM_Clients.txt"\r\nContent-Type: text/plain\r\n\r\n',
             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' }

问题是在处理 POST 时,在 PHP 的服务器上,变量 $_FILESempty

当我 error_log $_FILES : Array\n(\n)\n

我必须绝对经历这个变量,因为要做出太多改变

loading...

0回答

No Data

评论

暂时没有评论!