简体   繁体   English

使用http cloud云功能从Firebase云存储下载文件时,没有此类文件或目录

[英]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.

相关问题 使用云功能创建pdf文件并将其上传到firebase存储? (可以上传本地文件,但不能从云功能上传) - Create and upload pdf file to firebase storage using cloud functions? (can upload locally file, but not from cloud functions) 使用下载 url 和 Cloud Functions 从 Firebase 存储中删除文件 - Delete a file from firebase storage using download url with Cloud Functions 从云功能中删除云存储中的文件 - Delete file in cloud storage from cloud functions 将API文件下载到Firebase Cloud Storage? - Downloading an API file to Firebase Cloud Storage? 使用 Firebase Cloud Functions 将文件上传到 Firebase 存储时出错 - Error while uploading file to Firebase Storage using Firebase Cloud Functions Firebase:云函数+存储读取文件 - Firebase: Cloud Functions + Storage Read File 使用Cloud Functions REST API请求将文件存储在Firebase存储中 - Store file in Firebase Storage using Cloud Functions REST API request 上传到Firebase存储时如何使用Cloud Functions for FIrebase获取mp3文件的持续时间 - How to get the duration of a mp3 file using Cloud Functions for FIrebase when uploaded to firebase storage 云功能:删除Firestore文档时删除云存储上的文件 - Cloud Functions: Delete file on Cloud Storage when Firestore document is deleted 将存储在 Cloud Storage 中的 Apple Wallet.pkpass 文件从 Firebase Cloud Functions 更新到设备 - Updating Apple Wallet .pkpass file stored in Cloud Storage from Firebase Cloud Functions to device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM