Không thể thêm/tải tệp lên thùng amazon s3

lập trình


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

Những gì tôi đã thử:

Có thể lưu tệp trên ổ D nhưng trong khi đăng lên nhóm s3 hiển thị lỗi

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

Giải pháp 1

Thông báo lỗi hơi khó hiểu, nhưng khi bạn nhìn thấy nó, vấn đề sẽ rõ ràng:

Trích dẫn:

Xin hãy chỉ ra cụ thể một trong hai một inputStream hoặc một FilePath được đặt thành PUT dưới dạng đối tượng S3.

Lỗi cho bạn biết rằng bạn đã chỉ định cả hai MỘT InputStream Một FilePathkhông được hỗ trợ.

Gỡ bỏ FilePath tài sản từ bạn PutObjectRequest sự vật.

コメント

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