简体   繁体   English

S3 putobject throwing无效的URI:无法确定URI的格式

[英]S3 putobject throwing Invalid URI: The format of the URI could not be determined

I'm working on uploading local files to aws s3 in C# .net, and I'm using putObjectRequest to make the request to aws s3, however, I've just received a thrown exception: Invalid URI: The format of the URI could not be determined. 我正在将本地文件上传到C#.net中的aws s3,并且正在使用putObjectRequest向aws s3发出请求,但是,我刚收到一个抛出的异常: Invalid URI: The format of the URI could not be determined. . Here is what I'm doing: 这是我在做什么:

try {
    string testString = @"C:\Path\to\object files\file.jpg";
    PutObjectRequest objReq = new PutObjectRequest
    {
        Key = key,
        ContentType = "JPG",
        BucketName = bucket + "/" + FolderName,
        CannedACL = S3CannedACL.PublicReadWrite,
        FilePath = testString
    };
    PutObjectResponse response = s3Client.PutObject(objReq);
}
catch (Exception ex) 
{
    Console.WriteLine(ex.Message);
}

I carefully checked the BucketName , RegionEndPoint and ServiceURL , they have been set correctly, so I'm thinking the FilePath is not correct. 我仔细检查了BucketNameRegionEndPointServiceURL ,它们的设置正确,因此我认为FilePath不正确。 However, after searching the file path format in C#, I think I'm using the correct operator to escape the backslash. 但是,在C#中搜索文件路径格式后,我认为我正在使用正确的运算符来转义反斜杠。 Is there any other cause can lead to this exception? 还有其他原因可以导致此异常吗?

The entire stackTrace is like this: 整个stackTrace如下所示:

at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind) 在System.Uri.CreateThis(String uri,Boolean dontEscape,UriKind uriKind)

at System.Uri..ctor(String uriString) 在System.Uri..ctor(String uriString)

at Amazon.Runtime.Internal.EndpointResolver.DetermineEndpoint(IClientConfig config, IRequest request) 在Amazon.Runtime.Internal.EndpointResolver.DetermineEndpoint(IClientConfig配置,IRequest请求)

at Amazon.S3.Internal.AmazonS3PostMarshallHandler.ProcessRequestHandlers(IExecutionContext executionContext) 在Amazon.S3.Internal.AmazonS3PostMarshallHandler.ProcessRequestHandlers(IExecutionContext执行上下文)

at Amazon.S3.Internal.AmazonS3PostMarshallHandler.PreInvoke(IExecutionContext executionContext) 在Amazon.S3.Internal.AmazonS3PostMarshallHandler.PreInvoke(IExecutionContext executeContext)

at Amazon.S3.Internal.AmazonS3PostMarshallHandler.InvokeSync(IExecutionContext executionContext) 在Amazon.S3.Internal.AmazonS3PostMarshallHandler.InvokeSync(IExecutionContext执行上下文)

at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext) 在Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext执行上下文)

at Amazon.Runtime.Internal.Marshaller.InvokeSync(IExecutionContext executionContext) 在Amazon.Runtime.Internal.Marshaller.InvokeSync(IExecutionContext执行上下文)

at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext) 在Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext执行上下文)

at Amazon.S3.Internal.AmazonS3PreMarshallHandler.InvokeSync(IExecutionContext executionContext) 在Amazon.S3.Internal.AmazonS3PreMarshallHandler.InvokeSync(IExecutionContext executeContext)

at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext) 在Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext执行上下文)

at Amazon.Runtime.Internal.CallbackHandler.InvokeSync(IExecutionContext executionContext) 在Amazon.Runtime.Internal.CallbackHandler.InvokeSync(IExecutionContext执行上下文)

at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext) 在Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext执行上下文)

at Amazon.S3.Internal.AmazonS3ExceptionHandler.InvokeSync(IExecutionContext executionContext) 在Amazon.S3.Internal.AmazonS3ExceptionHandler.InvokeSync(IExecutionContext执行上下文)

at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext) 在Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext执行上下文)

at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeSync(IExecutionContext executionContext) 在Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeSync(IExecutionContext执行上下文)

at Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext executionContext) 在Amazon.Runtime.Internal.PipelineHandler.InvokeSync(IExecutionContext执行上下文)

at Amazon.Runtime.Internal.MetricsHandler.InvokeSync(IExecutionContext executionContext) 在Amazon.Runtime.Internal.MetricsHandler.InvokeSync(IExecutionContext执行上下文)

at Amazon.Runtime.Internal.RuntimePipeline.InvokeSync(IExecutionContext executionContext) 在Amazon.Runtime.Internal.RuntimePipeline.InvokeSync(IExecutionContext执行上下文)

at Amazon.Runtime.AmazonServiceClient.Invoke[TRequest,TResponse](TRequest request, IMarshaller`2 marshaller, ResponseUnmarshaller unmarshaller) 在Amazon.Runtime.AmazonServiceClient.Invoke [TRequest,TResponse](TRequest请求,IMarshaller`2编组器,ResponseUnmarshaller编组器)处

at Amazon.S3.AmazonS3Client.PutObject(PutObjectRequest request) 在Amazon.S3.AmazonS3Client.PutObject(PutObjectRequest请求)

at Camera_Capture.UploadFileToAmazonS3(String Filepath, String camstring, String SerialNumber) in C:\\path\\to\\Program.cs:line 371 在Camera_Capture.UploadFileToAmazonS3(String Filepath,String camstring,String SerialNumber)在C:\\ path \\ to \\ Program.cs:line 371

It turns out to be a very misleading error message. 事实证明这是一个非常令人误解的错误消息。 The problem is from AmazonS3Client(accesskey, secretkey, AmazonS3Config config); 问题出在AmazonS3Client(accesskey, secretkey, AmazonS3Config config); was not getting the RegionEndpoint when AmazonS3Config was constructed. 没有得到的RegionEndpointAmazonS3Config构建。 I changed the S3 client constructor to AmazonS3Client(accesskey, secretkey, RegionEndpoint.USWest2); 我将S3客户端构造函数更改为AmazonS3Client(accesskey, secretkey, RegionEndpoint.USWest2); and it resolved the error for me. 它为我解决了错误。 I think Amazon itself should return a message of RegionEndpoint of config is null rather than this misleading message Invalid URI: The format of the URI could not be determined that .net will throw, because it can be caused by many other reasons. 我认为亚马逊本身应该返回RegionEndpoint of config is nullRegionEndpoint of config is null消息RegionEndpoint of config is null而不是此误导性消息Invalid URI: The format of the URI could not be determined .net将抛出Invalid URI: The format of the URI could not be determined ,因为它可能是由许多其他原因引起的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM