相关疑难解决方法(0)

如何使用nodejs将内存文件数据上传到谷歌云存储?

我正在从网址读取图像并进行处理.我需要将此数据上传到云存储中的文件,目前我正在将数据写入文件并上传此文件然后删除此文件.有没有办法可以将数据直接上传到云存储?

static async uploadDataToCloudStorage(rc : RunContextServer, bucket : string, path : string, data : any, mimeVal : string | false) : Promise<string> {
if(!mimeVal) return ''

const extension = mime.extension(mimeVal),
      filename  = await this.getFileName(rc, bucket, extension, path),
      modPath   = (path) ? (path + '/') : '',
      res       = await fs.writeFileSync(`/tmp/${filename}.${extension}`, data, 'binary'),
      fileUrl   = await this.upload(rc, bucket, 
                            `/tmp/${filename}.${extension}`,
                            `${modPath}${filename}.${extension}`)

await fs.unlinkSync(`/tmp/${filename}.${extension}`)

return fileUrl
}

static async upload(rc : RunContextServer, bucketName: string, filePath : string, destination : string) : Promise<string> { …
Run Code Online (Sandbox Code Playgroud)

node.js google-cloud-storage

8
推荐指数
2
解决办法
3333
查看次数

标签 统计

google-cloud-storage ×1

node.js ×1