heroku上的节点文件系统访问错误

我有一个简单的代码,使用快速fs将选定的图像保存到文件系统

exports.upload = function(req, res) { var photoInfo = req.body, file = req.files.file, fileType = file.type.slice(6); //attaching the fileType to photoInfo because fileType is part of req.files, not part of req.body photoInfo.fileType = fileType; var newPhoto = new Photo(photoInfo); Photo.create(newPhoto, function(err, insertedPhotoInfo){ if (err) throw err; var photoId = insertedPhotoInfo._id; //create directory if it does not exist already fs.exists(__directory, function(exists) { if (!exists) { fs.mkdir(__directory, function(err, data){ if (err) throw err; }); } }); //create the file with the unique id created by mongo as its name // http://www.hacksparrow.com/handle-file-uploads-in-express-node-js.html // get the temporary location of the file var tmpPath = file.path; // set where the file should actually exists - in this case it is in the "images" directory // var targetPath = './uploads/' + req.files.file.name; // move the file from the temporary location to the intended location fs.rename(tmpPath, __directory + '/' + photoId + '.' + fileType, function(err){ if (err) throw err; // var reader = new FileReader(); // delete the temporary file, so that the explicitly set temporary upload dir does not get filled with unwanted files fs.unlink(tmpPath, function() { if (err) throw err; res.send(insertedPhotoInfo); }); }); }); }; 

这在localhost上完美工作,但是一旦我部署到heroku,我得到ENOENT,打开错误。 它似乎失去了访问的FS。 我认为这是因为heroku只有短暂的文件系统。

会有任何解决这个? 或者我需要build立一个单独的VM /静态文件服务器?