node.js - 将包含可变数据的文件上传到 Google Cloud Storage
问题描述
我想上传一个文本文件,其中包含我的服务器之前收到的一些变量。例如,当用户 1 发送一些数据时,我想创建并上传一个名为USER1.txt的文件,其中包含USER1的详细信息。同样,当 USER2 发送他的数据时,会创建一个包含USER2详细信息的新文件USER2.txt并将其上传到 Google Cloud Storage。
这是我尝试过的
const filename = "./details.txt";
const content = 'this contains some random variables declared previously';
fs.writeFileSync(filename,content);
await savetocloud('my-bucket',filename);
});
const savetocloud = async function(bucketName, filename) {
async function uploadFile() {
await storage.bucket(bucketName).upload(filename,{
gzip:true,
metadata:{
cacheControl: 'public, max-age=31536000',
}
});
console.log('${filename} uplaoded to ${bucketname}');
}
uploadFile().catch(console.error);
该程序运行良好,并且在 localhost 中执行时也会上传文件。但是,当我将此应用程序部署到应用程序引擎时,它不起作用。
编辑:这是我的 app.yaml 文件。
runtime: nodejs12
automatic_scaling:
target_cpu_utilization: 0.85
handlers:
- url: /javascript
static_dir: javascript
- url: /style
static_dir: style
- url: /coverphoto
static_dir: coverphoto
- url: /slidephoto
static_dir: slidephoto
解决方案
推荐阅读
- r - 如何从存储在 R 上的矩阵中的坐标中提取 3D 数组的多个值?
- azure-cloud-services - 在 Azure 云服务中以编程方式将暂存槽交换到生产槽
- java - 我可以更改 Swagger 显示的默认定义吗?
- javascript - 如何访问嵌套数组中的数据?
- python - 使用 Django filter() 时的动态键
- php - WooCommerce 弹出窗口可在税/无税之间切换
- angular - 从列表中删除项目
- c - 使用指针显示/更改以前创建的数组在用户输入后不起作用
- android - 获取文件路径而不在内存中加载文件?
- html - 如何阻止物化导航栏选项卡下划线和更改颜色?