如何使用Rest API在Google Cloud Storage中下载文件 [英] How to download files in Google Cloud Storage using rest api

查看:126
本文介绍了如何使用Rest API在Google Cloud Storage中下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:与dcm API相关的存储桶中存储了多个文件夹和许多文件.(单击,展示,每日汇总文件等). https://console.cloud.google.com/storage/browser/dcmaccountno

Scenario: there are multiple folders and many files stored in storage bucket related to dcm API.(click,impression,daily aggregate files etc). https://console.cloud.google.com/storage/browser/dcmaccountno

是否可以使用rest api下载文件,当前我具有服务帐户和私钥. 我们对goog云存储没有太多了解,因此任何小小的帮助都是非常可观的.

Is it possible to download files using rest api and currently i have service account and private key. we dont have much exposure towards goog cloud storage hence any small help would be really appreciable.

谢谢您的帮助!

推荐答案

使用rest API,您可以按照以下链接中已经介绍的以下方式从Google存储空间下载/上传文件:

Using rest API you can download/upload files from google storage in the following way that I already did in the below-mentioned link:

参考: https://stackoverflow.com/a/53955058/4345389

您可以通过以下方式使用DownloadData方法来代替WebClient的UploadData方法:

Instead of UploadData method of WebClient, you can use DownloadData method in the following way:

// Create a new WebClient instance.
using (WebClient client= new WebClient())
{
  client.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + bearerToken);
  client.Headers.Add(HttpRequestHeader.ContentType, "application/octet-stream");
// Download the Web resource and save it into a data buffer.
byte[] bytes = client.DownloadData(body.SourceUrl);
MemoryStream memoryStream = new MemoryStream(bytes);
// TODO write further funcitonality to write the memorystream
}

根据您的要求进行一些调整.

Do some tweaks as per your requirements.

这篇关于如何使用Rest API在Google Cloud Storage中下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆