Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Express 使用react native将图像上载到heroku_Express_React Native_Heroku - Fatal编程技术网

Express 使用react native将图像上载到heroku

Express 使用react native将图像上载到heroku,express,react-native,heroku,Express,React Native,Heroku,我正在尝试将图像从react native上传到public/images/文件夹中的heroku express应用程序。它会向我显示成功消息,但“图像”文件夹中没有图像。 同时,当我在localhost上尝试这段代码时,效果很好 router.post('/add', (req, res) => { let imageFile = req.files.photo; let fileName = Date.now(); let imgName = fileName

我正在尝试将图像从react native上传到public/images/文件夹中的heroku express应用程序。它会向我显示成功消息,但“图像”文件夹中没有图像。 同时,当我在localhost上尝试这段代码时,效果很好

router.post('/add', (req, res) => {
    let imageFile = req.files.photo;
    let fileName = Date.now();
    let imgName = fileName+req.files.photo.name;
    let dirName = __dirname.replace('routes','public')
    dirName = dirName+'/images/';
    let path = dirName+imgName;
    imageFile.mv(path, (err)=> {
        if (err) {
            return res.status(501).json({
                message: 'error'
            });
        } else {
            return res.status(200).json({
                message: 'success'
            })
        }
    });
})
Heroku文件系统是,您不能使用它在运行时持久存储任何内容。 相反,您可以使用来自的附加组件来实现您的存储需求。 对于您的特定用例,听起来可能是一个很好的匹配。他们的免费计划为您提供10GB的存储空间。
如前所述,您可以轻松地从node.js代码将图像上传到cloudinary。

但我已经有应用程序在heroku上运行,运行良好。您的应用程序仍将在heroku上运行。你只需在Heroku应用程序中添加一个免费插件,并添加几行代码将图像上传到Cloudinary即可。Amazon S3是另一个流行选项。看见