我们正在尝试从GCP存储桶控制台下载文件,但是性能确实很慢。即使是一个50 MB的文件,也要花费大约2到3分钟的时间,而且变化范围也很大。我们正在使用storageclient downloadobjects方法
我们有一个适用于GCP上传的代码,该代码可以更快地上传GB的文件。在下载方面是否存在特定问题。
我们正在使用C#代码进行上传和下载。
class Program
{
public static void Main(string[] args)
{
GoogleCredentials gcpCreds = new GoogleCredentials()
{
private_key = "-----BEGIN PRIVATE KEY-----PrivateKey-----END PRIVATE KEY-----\n",client_email = "client_email",type = "service_account"
};
var credentials = GoogleCredential.FromJson(JsonConvert.SerializeObject(gcpCreds));
// var credentials= GoogleCredential.GetapplicationDefault();
var storage = Storageclient.CreateAsync(credentials).Result;
string localPath,directoryPath,localFileName,objectname,bucketName;
directoryPath = "localpathstring";
objectname = "SourceFileName";
localFileName = objectname;
localPath = directoryPath + "\\" + localFileName;
bucketName="bucketName";
FileStream fs = new FileStream(localPath,FileMode.OpenOrCreate);
//Code to download with progress bar
DownloadObjectOptions option = new DownloadObjectOptions();
using (fs)
{
var progress = new Progress<IDownloadProgress>(
p => Console.WriteLine($"bytes: {p.BytesDownloaded},status: {p.Status},"));
storage.DownloadObject(bucketName,fs,option,progress);
}
}