Node.js AWS&x27的替代方案;google云/存储中的bucket.putObject()方法

Node.js AWS&x27的替代方案;google云/存储中的bucket.putObject()方法,node.js,google-cloud-storage,Node.js,Google Cloud Storage,我想使用google云/存储包模拟以下AWS调用 const params = { Body: data, Key: key, ContentType: type }; return new Promise(function (resolve, reject) { bucket.putObject(params, func

我想使用google云/存储包模拟以下AWS调用

const params = {
                Body: data,
                Key: key,
                ContentType: type
            };
            return new Promise(function (resolve, reject) {
                bucket.putObject(params, function(error, data) {
                    if (error) {
                        console.log('ERROR: ', error);
                        reject(error);
                    }
                    resolve(data);                  
                });
            })
在上面的调用中,如果我在Key参数中传递一些目录层次结构,那么将创建文件夹结构并正确放置文件

例如,如果我将密钥作为 根目录/test\u文件夹/input\u文件.json 然后文件将被放置为 S3:///root/test\u folder/input\u file.json

我在谷歌云/存储中找不到类似的调用。 如果我使用

<bucket>.upload()
file.save()
如果我使用

<bucket>.upload()
file.save()
方法,我可以将数据放入存储,但现在我无法将其放在特定目录下

await file.save(contents);

我需要某种方法将内容放入谷歌存储的目录结构中,而目录结构可能不存在。

很抱歉,我错了。这可以通过file.save()方法简单地完成。 我们只需要指定路径和文件名

const {Storage} = require('@google-cloud/storage');

const storage = new Storage();
    const myBucket = storage.bucket('bucket');

    const file = myBucket.file('xxx/yyy/my-file', { generation: 0 });
    const contents = 'This is the contents of the file.';

    file.save(contents, function(err) {
      if (err) {
        file.deleteResumableCache();
      }
    });
上面的命令将文件存储在

bucket/xxx/yyy

我可以用file.save()和file.move()的组合来实现这一点,但我认为这不是一个很好的方法!对不起,我错了!这只能通过file.save()方法完成!!