【问题标题】:Download image files from google cloud storage bucket to IOS localstorage using meteor使用流星从谷歌云存储桶下载图像文件到IOS本地存储
【发布时间】:2019-03-30 19:10:25
【问题描述】:

我正在使用 Meteor 项目将图像从 iOS 设备上传到谷歌云,并将相同的图像下载到 iOS 设备。

上传图片时我没有遇到任何问题,它存储在谷歌存储桶中。我面临的问题是在下载图像时,我使用下面的代码下载服务​​器路径上的图像。

bucket.file(srcFilename).download(options);

我想下载图像并将其存储在 iOS 设备上。 当我尝试使用 createReadStream 读取文件时,我的应用卡住了,没有任何进展(没有得到任何回调)。

  bucket.file(srcFilename).createReadStream()
  .on('error', function(err) {
    console.log("error");
  })
  .on('response', function(response) {
    // Server connected and responded with the specified status and
    console.log("response");
  })
  .on('end', function() {
    // The file is fully downloaded.
    console.log("The file is fully downloaded.");
  })

我希望在将图像下载到 iOS 设备时不会丢失任何内容。我看了看,但找不到任何其他选项来做同样的事情。

非常感谢您在这方面的任何帮助,因为我被困在这一点上。

【问题讨论】:

    标签: node.js meteor google-cloud-storage


    【解决方案1】:

    我使用下面的代码从谷歌云获取文件并下载我转换为二进制格式的块。然后我使用这种二进制格式从客户端显示图像并存储在我的本地存储中。

    var chunkNew = new Buffer('');
    
     bucket.file(srcFilename).createReadStream().on('data', function (chunk) {
        chunkNew = Buffer.concat([chunkNew,chunk]);
      })
      .on('end', function() {
        // The file is fully downloaded.
        callback(null, chunkNew.toString('base64'));
      })
    

    更多信息可以在这个链接http://codewinds.com/blog/2013-08-04-nodejs-readable-streams.html 中找到,它使用数据块将图像显示为数组缓冲区。

    【讨论】:

      猜你喜欢
      • 2019-04-13
      • 1970-01-01
      • 2019-02-09
      • 2020-01-18
      • 2018-07-11
      • 2017-03-28
      • 2016-08-09
      • 2017-06-11
      • 1970-01-01
      相关资源
      最近更新 更多