微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Cloud Function下载URL,然后上传到Cloud Storage存储桶

如何解决Cloud Function下载URL,然后上传到Cloud Storage存储桶

以下代码运行良好。我收到“文件下载”日志,然后显示状态200代码,但此后存储桶中存在的文件大小仅为20B,并且为空。

我曾尝试查看日志文件,但其中填充了很多参数,例如socketPath和许多其他参数。

但是,我认为有1个潜在相关的日志文件条目可能是导致此结果的原因(连接:关闭),但无法找出解决方法。请查看附件图片

cloud function log entry

const {Storage} = require('@google-cloud/storage');
    
exports.writetoBucket = (req,res) => {
    const http = require('http');
    const fs = require('fs');
    
    const file = fs.createWriteStream("/tmp/pp-monthly-update.txt");
    const request = http.get("http://prod.publicdata.landregistry.gov.uk.s3-website-eu-west-1.amazonaws.com/pp-monthly-update.txt",function(response) {
      response.pipe(file);
    });
    
    
    console.log('file downloaded');
    
    // Imports the Google Cloud client library
    const {Storage} = require('@google-cloud/storage');
    
    // Creates a client
    const storage = new Storage();
    const bucketName = 'landregistry_pricepaid_month';
    const filename = '/tmp/pp-monthly-update.txt';
    
    // Uploads a local file to the bucket
    storage.bucket(bucketName).upload(filename,{
      gzip: true,Metadata: {
        cacheControl: 'no-cache',},});
    
    res.status(200).send(`${filename} uploaded to ${bucketName}.`);
    
};

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。