[英]no such file or directory when downloading a file from firebase cloud storage using http cloud cloud functions
I wrote a .txt file in firebase cloud storage and i want to download that .txt file and sending it to another server validation. 我在Firebase云存储中编写了一个.txt文件,我想下载该.txt文件并将其发送给另一台服务器验证。 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. 有什么方法可以从云存储下载该文件,以及如何获取存储的文件URL作为云功能的响应。
You are trying to download a file to a non-writable (and non-existent) folder in the Cloud Functions runtime. 您正在尝试将文件下载到Cloud Functions运行时中的不可写(和不存在)文件夹中。 There is no such folder as /Users. 没有/ Users这样的文件夹。 That exists only on your own computer. 那只存在于您自己的计算机上。 The only writable folder in Cloud Functions is os.tmpdir()
, or /tmp. Cloud Functions中唯一可写的文件夹是os.tmpdir()
或/ tmp。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.