duancan1900 2017-02-16 10:09
浏览 80
已采纳

无法使用Node.js中的请求模块传输大型文件

In a Node.js project I have to transfer file from computer to server. I can send file if file size is small i.e. 2mb but unable to send file if it is more than this size. Here is my code as follows:

var url1 = 'http://beta.xxxxx.com/Xbox/xxxx/index.php/info/xxxxx';
var csvenriched = APPDATApath+'/xxxx/users/'+userId+'/programs/'+programName+'/'+foldername+'/Data_'+tmpstmp+'.csv';

var req = request.post(url1, function (err, resp, body1) {  
    if (err) {
        console.log('REQUEST RESULTS:'+err+resp.statusCode+body1);
        res.send(err); return false;
    } else {
        res.send(body1); return false;
    }
});

var form = req.form();

form.append('file', fs.createReadStream(csvenriched));

On the PHP side where I am sending data code is as follows:

public function actionSavetestvideo() {
    if (!empty($_FILES)) {
        $path = Yii::$app->basePath.'/testfiles/'.$_FILES['file']['name'];
        if (move_uploaded_file($_FILES['file']['tmp_name'], $path)) {
            return 'uploaded';
        } else {
            return 'error'.$_FILES["file"]["error"];
        }
    } else {
        return $_FILES;
    }
}

I know there are answers on internet in case if I have to upload file on Node.js server But in my case I have to transfer file using request module from Node.js to PHP server.

It is working fine in case if file size is small but not if CSV file size is large.

The one thing which I have noticed that if file size is large then if (!empty($_FILES)){} on php side went failed. So I don't think there is issue on PHP side. Please suggest what should I modify there?

  • 写回答

2条回答 默认 最新

  • duanqing2209 2017-02-23 06:36
    关注

    I agreed from mscdex the problem is on PHP side. After increasing upload_max_filesize from 2MB to 50MB it was not working, till then I have restarted the Apache Server again.

    On Restart the Apache server, it starts working perfectly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境