【解決方法】Amazon 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 そして ある FilePath、これはサポートされていません。

を削除します。 FilePath あなたからの財産 PutObjectRequest 物体。

コメント

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