Reputation: 797
I'm using File System module to stream a PDF file and then, to access that file for later usage. It works when I try it in the compiler, but when I do a deploy in Dialogflow, it fails with error:
Error: EROFS: read-only file system, open 'filename.pdf' at Error (native)
This is the code:
const fs = require('fs');
const request = require('request');
var downloadRequest = {
url: "http://www.axmag.com/download/pdfurl-guide.pdf",
method: 'GET'
}
var file = fs.createWriteStream("filename.pdf");
request(downloadRequest).pipe(file);
file.on('finish', function(){
var downloadedFile = fs.createReadStream("filename.pdf");
// Other code which accesses 'downloadedFile' takes place below
...
});
Is there anything that can be done to handle this error?
Upvotes: 1
Views: 4681
Reputation: 11978
As we discussed, you're deploying code using Firebase Functions. FF are read-only systems, as part of its stateless system, meaning that you cannot save files persistently (as that would conflict with the stateless system, and having these files persist across every execution server/environment wouldn't be guaranteed).
To host content dynamically, you would need to use another system for hosting files. This could be through Firebase cloud storage instead of saving in the process, or just storing the file contents in memory.
Upvotes: 2