I am trying to save a file to an S3 bucket. I am copying the file to a temp location just to prove (to me) the file exists and is accessible. Of course the copy works without issue.
The last line keeps throwing an exception and the details say "Object reference not set to an instance of an object".
File.Copy(fullFilePath, "C:\\Temp\\" + fullFileName);
IAmazonS3 client = null;
if (Session["s3Client"] != null) {
client = (IAmazonS3)Session["s3Client"];
} else {
client = new AmazonS3Client(RegionEndpoint.GetBySystemName(AWS_REGION));
} // if
PutObjectRequest putRequest = new PutObjectRequest {
BucketName = S3_BUCKET_NAME,
Key = fullFileName
};
using (FileStream stream = new FileStream(fullFilePath, FileMode.Open)) {
putRequest.InputStream = stream;
// Put object
PutObjectResponse response = client.PutObject(putRequest);
}
I have tried a few things with the S3 call:
- Different key (tried the word 'blah')
- Different bucket
- Sending the file as a path rather than a stream
There is not a lot else for me to try since I am really only providing 3 fields.
I am trying to leave authentication outside of the code so the host machine can control it.
Any ideas?
Thanks a lot.
Edit:
at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.FetchCredentials()
at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentials()
at Amazon.Runtime.Internal.CredentialsRetriever.PreInvoke(IExecutionContext executionContext)
at Amazon.Runtime.Internal.CredentialsRetriever.InvokeSync(IExecutionContext executionContext)
at Amazon.Runtime.Internal.RetryHandler.InvokeSync(IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeSync(IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeSync(IExecutionContext executionContext)
at Amazon.S3.Internal.AmazonS3ExceptionHandler.InvokeSync(IExecutionContext executionContext)
at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeSync(IExecutionContext executionContext)
at Amazon.Runtime.Internal.MetricsHandler.InvokeSync(IExecutionContext executionContext)
at Amazon.Runtime.Internal.RuntimePipeline.InvokeSync(IExecutionContext executionContext)
at Amazon.Runtime.AmazonServiceClient.Invoke[TResponse](AmazonWebServiceRequest request, InvokeOptionsBase options)
at MyCode.aspx.cs:line 260