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