如何使用Rest API在Google Cloud Storage中下载文件

编程入门 行业动态 更新时间:2024-10-19 16:33:21
本文介绍了如何使用Rest API在Google Cloud Storage中下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

场景:与dcm API相关的存储桶中存储了多个文件夹和许多文件.(单击,展示,每日汇总文件等). console.cloud.google/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). console.cloud.google/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:

参考: stackoverflow/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中下载文件

本文发布于:2023-11-28 10:02:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641952.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   文件   Rest   Google   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!