I wrote a .txt file in firebase cloud storage and i want to download that .txt file and sending it to another server validation. I tried so many ways to download that file but i am getting an error like
"Error: ENOENT: no such file or directory, open '/Users/vijayasrivuddanti/Downloads/download.txt'
at Error (native)
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '/Users/vijayasrivuddanti/Downloads/download.txt'"
This is the code i tried :
function writetofile(){
const storage = new Storage();
const bucket = storage.bucket('deyapay-192704.appspot.com');
console.log("date",Date.now());
var datetime = new Date();
console.log("iso", new Date().toISOString().slice(0,10));
const file = bucket.file(new Date().toISOString().slice(0,10)+".txt"); // It create the file in the bucket in ascii format and save as today date format.
const a = new Date().toISOString().slice(0,10)+".ascii"
console.log("filename",a);
var storageRef = admin.storage().bucket();
const uploadStream = file.createWriteStream();
uploadStream.on('error', function(err) {
console.log("write err",err);
});
finalnachaformat.forEach(function(v) { // It takes the each value in
finalnachaformat in every loop.
console.log("v",v)
console.log("gii");
uploadStream.write(v+ '\n'); // and write data into file.
console.log("looping function",v);
})
console.log("successfully uploaded")
uploadStream.end();// writing end
//-
// Download a file into memory. The contents will be available as the second
// argument in the demonstration below, `contents`.
//-
file.download(function(err, contents) {});
//-
// Download a file to a local destination.
//-
file.download({
destination: '/Users/vijayasrivuddanti/Downloads/download.txt'
}, function(err) {
console.log("error",err);
});
//-
// If the callback is omitted, we'll return a Promise.
//-
file.download().then(function(data) {
const contents = data[0];
console.log("entred");
res.send("ok");
});
How to solve that error? Is there any way for downloading that file from cloud storage and how to get the stored file URL as response from cloud functions.