0

I am working on a project where I need to pass a file to an external API from a signed url.

My code is as follows:

public void UploadFile(string localPath)
   {
       string objectName = null;
       string path = System.Web.HttpContext.Current.Server.MapPath(Resource.GoogleSigningKey); //path to google cloud key
       var credential = GoogleCredential.FromFile(path);
       var storage = StorageClient.Create(credential);
       using (var f = File.OpenRead(localPath))
           {
               objectName = Path.GetFileName(localPath);
               storage.UploadObject(Resource.BucketName, objectName, null, f);
           }
   }

Here I am uploading the file to Google Cloud Storage to create the signed url

this code works perfectly on local machine, but when I upload it to IIS, I get an error as follows "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 21X.XX.XXX.XXX:ZZZ"

The IIS version is 7.5.

Do I have to do some configuration settings on google cloud storage for production.

I am getting the following error:

An error occurred while sending the request. at Google.Cloud.Storage.V1.StorageClientImpl.UploadHelper.CheckFinalProgress() at Google.Cloud.Storage.V1.StorageClientImpl.UploadHelper.Execute() at Google.Cloud.Storage.V1.StorageClientImpl.UploadObject(String bucket, String objectName, String contentType, Stream source, UploadObjectOptions options, IProgress`1 progress) 

Edit 1 The same code works when I create a windows form application and execute it on the server. Except for

string path = System.Web.HttpContext.Current.Server.MapPath(Resource.GoogleSigningKey);

I am using

string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var credential = GoogleCredential.FromFile(path + @"\DataFiles\TestStorage.json");

Edit 2

The IIS server is configured in a proxy setting, does google cloud accessing need separate configuration for proxy settings

Please help

Thank you

Soni Sol
  • 2,367
  • 3
  • 12
  • 23
JPais
  • 115
  • 2
  • 14
  • can you catch Google.GoogleApiException and provide the exact error message it is throwing? – Mahesh Khond Nov 08 '19 at 12:30
  • What is the credential `path`? Remember that IIS is not running as a user, it is running as a service. This means that the path must exist to services. – John Hanley Nov 08 '19 at 14:34
  • @JohnHanley: Its is a file in the AppData folder: "~/App_Data/XXXX.json", hence I am doing a Server.MapPath in the previous line. – JPais Nov 09 '19 at 06:57
  • The path `~/App_Data/XXXX.json` is not valid for a service. Specify a full path. – John Hanley Nov 09 '19 at 19:03
  • This is the error I am gettingAn error occurred while sending the request. at Google.Cloud.Storage.V1.StorageClientImpl.UploadHelper.CheckFinalProgress() at Google.Cloud.Storage.V1.StorageClientImpl.UploadHelper.Execute() at Google.Cloud.Storage.V1.StorageClientImpl.UploadObject(String bucket, String objectName, String contentType, Stream source, UploadObjectOptions options, IProgress`1 progress) – JPais Nov 11 '19 at 09:46
  • Please edit the details into the question. Are you able to *fetch* anything from GCS? Are you sure your server is configured to allow outbound connections? – Jon Skeet Nov 11 '19 at 10:17
  • Updated, I tried the same on the server with a winform application, (code updated in the question), it works. So I think the server allows outbound connection. – JPais Nov 11 '19 at 10:39
  • Do you see a log of the connection attempt on Google Side? and [here](https://stackoverflow.com/questions/55967800/upload-files-to-google-cloud-storage-using-c-sharp) is a similar case that the issue was the firewall rules so can you check on this. – Soni Sol Dec 10 '19 at 01:16

0 Answers0