无法在亚马逊 s3 存储桶上添加/上传文件


File.WriteAllBytes("D:/" + model.FileBase.FileName, model.FileBase.Data);
               byte[] bytes = Convert.FromBase64String(model.file);
               using (var inputStream = new MemoryStream(model.FileBase.Data))
               {
                   inputStream.Position = 0;
                   await s3Client.PutObjectAsync(new PutObjectRequest
                   {
                       InputStream = inputStream,
                       ContentType = MimeMapping.GetMimeMapping(model.fileName + model.fileExtension),
                       BucketName = model.bucketName,
                       Key = model.fileName,
                       FilePath = model.destination,
                       CannedACL = S3CannedACL.BucketOwnerFullControl
                   });
               }

我尝试过的:

能够将文件保存在 D 驱动器上,但在发布到 s3 存储桶时显示错误

Please specify one of either an InputStream or a FilePath to be PUT as an S3 object.'
at Amazon.S3.Internal.AmazonS3PreMarshallHandler.ProcessPreRequestHandlers(IExecutionContext executionContext)
   at Amazon.S3.Internal.AmazonS3PreMarshallHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Amazon.S3.Internal.AmazonS3ExceptionHandler.<InvokeAsync>d__1`1.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Amazon.Runtime.Internal.ErrorCallbackHandler.<InvokeAsync>d__5`1.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Amazon.Runtime.Internal.MetricsHandler.<InvokeAsync>d__1`1.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at WebApi.Controllers.S3BucketController.<Post>d__2.MoveNext() in C:\Users\Satya\Downloads\WebApi\Controllers\S3BucketController.cs:line 62

解决方案1

错误消息有点令人困惑,但是一旦你看到它,问题就很明显了:

引用:

请明确说明 其中之一 要作为 S3 对象 PUT 的 InputStream 或 FilePath。

该错误告诉您您已指定 两个都 一个 InputStream A FilePath,不受支持。

去除 FilePath 来自你的财产 PutObjectRequest 目的。

コメント

タイトルとURLをコピーしました