Impossible d’ajouter/télécharger un fichier sur le compartiment Amazon S3

la programmation


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
                   });
               }

Ce que j’ai essayé :

Capable d’enregistrer le fichier sur le lecteur D, mais lors de la publication sur le compartiment s3, une erreur s’affiche

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

Solution 1

Le message d’erreur est légèrement déroutant, mais une fois que vous le voyez, le problème est évident :

Citation:

Veuillez préciser l’un ou l’autre un InputStream ou un FilePath à PUT en tant qu’objet S3.

L’erreur vous indique que vous avez spécifié les deux un InputStream et un FilePathce qui n’est pas pris en charge.

Retirer le FilePath propriété de votre PutObjectRequest objet.

コメント

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