【发布时间】:2020-10-13 12:31:54
【问题描述】:
我的服务器中有一个名为“space.jpg”的本地文件。
现在我想用新名称将此文件上传到 GCP 存储桶。
我可以使用以下代码成功上传此文件:
const myBucket= gc.bucket('my-bucket')
app.post('/create_file', async (req, res, next) => {
myBucket.upload("space.jpg")
}
我在服务器中的文件结构
- server.js
- 空间.jpg
现在我想在用户请求时上传这个带有随机 id 的文件。
例如
app.post('/create_file', async (req, res, next) => {
// spaceId = random string
// upload space.jpg to myBucket with the name spaceId
}
如何用新名称上传?
【问题讨论】:
标签: node.js google-cloud-storage