• Проблема при попытке загрузки файла в s3 bucket cloud.ru evolution?

    @Wrrrrit Автор вопроса
    Михаил Р., для подключения использую в s3Client.AccessKeyId, исходя из ответов поддержки, bucketRegion не использую вообще
    Написано
  • Проблема при попытке загрузки файла в s3 bucket cloud.ru evolution?

    @Wrrrrit Автор вопроса
    Alexey Dmitriev, спасибо за совет, прямо сейчас разбираюсь с aws cli, подключился только с помощью cyberduck
    Написано
  • Проблема при попытке загрузки файла в s3 bucket cloud.ru evolution?

    @Wrrrrit Автор вопроса
    Михаил Р.,
    using Microsoft.AspNetCore.Mvc;
    using AutoMapper;
    using Microsoft.AspNetCore.Http;
    using Amazon.S3;
    using Amazon.S3.Model;
    using Amazon;
    using Amazon.Runtime;
    using filer_sharing_api.Models;
    using System.IO;

    namespace filer_sharing_api.Controllers
    {
    [Route("api/[controller]")]
    [ApiController]
    public class BucketController : Controller
    {

    private readonly IAmazonS3 _s3Client;
    //AmazonS3Client initialization
    public BucketController(S3Client s3Client)
    {
    if (string.IsNullOrEmpty(s3Client.AccessKeyId) || string.IsNullOrEmpty(s3Client.SecretAccessKey) || s3Client.BucketRegion == null)
    {
    throw new Exception("wrong credits in s3Client");
    }

    _s3Client = new AmazonS3Client(s3Client.AccessKeyId, s3Client.SecretAccessKey, s3Client.configsS3);
    }

    ///
    /// Shows how to upload a file from the local computer to an Amazon S3
    /// bucket.
    ///
    /// An initialized Amazon S3 client object.
    /// The Amazon S3 bucket to which the object
    /// will be uploaded.
    /// The object to upload.
    /// The path, including file name, of the object
    /// on the local computer to upload.
    /// A boolean value indicating the success or failure of the
    /// upload procedure.
    [HttpPut("/sendfile")]
    public async Task UploadFileAsync(
    //deleted IS3Clent parameter
    string bucketName,
    string objectName,
    string filePath)
    {

    var request = new PutObjectRequest
    {
    BucketName = bucketName,
    Key = objectName,
    FilePath = filePath,
    };
    //using _s3Client patameter as default
    var response = await _s3Client.PutObjectAsync(request);
    if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
    {
    Console.WriteLine($"Successfully uploaded {objectName} to {bucketName}.");
    return true;
    }
    else
    {
    Console.WriteLine($"Could not upload {objectName} to {bucketName}.");
    return false;
    }

    }

    }

    }

    код для подключения взят из документации cloud.ru. Kод для отправки файла из документации aws, ссылку на которую указана в документации cloud.ru

    ошибка:
    Amazon.S3.AmazonS3Exception: Specified bucket does not exist

    ---> Amazon.Runtime.Internal.HttpErrorResponseException: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.

    at Amazon.Runtime.HttpWebRequestMessage.ProcessHttpResponseMessage(HttpResponseMessage responseMessage)

    at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken)

    at Amazon.Runtime.Internal.HttpHandler`1.InvokeAsync[T](IExecutionContext executionContext)

    at Amazon.Runtime.Internal.RedirectHandler.InvokeAsync[T](IExecutionContext executionContext)

    at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext)

    at Amazon.S3.Internal.AmazonS3ResponseHandler.InvokeAsync[T](IExecutionContext executionContext)

    at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)

    --- End of inner exception stack trace ---

    at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionStream(IRequestContext requestContext, IWebResponseData httpErrorResponse, HttpErrorResponseException exception, Stream responseStream)

    at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionAsync(IExecutionContext executionContext, HttpErrorResponseException exception)

    at Amazon.Runtime.Internal.ExceptionHandler`1.HandleAsync(IExecutionContext executionContext, Exception exception)

    at Amazon.Runtime.Internal.ErrorHandler.ProcessExceptionAsync(IExecutionContext executionContext, Exception exception)

    at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)

    at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)

    at Amazon.Runtime.Internal.Signer.InvokeAsync[T](IExecutionContext executionContext)

    at Amazon.S3.Internal.S3Express.S3ExpressPreSigner.InvokeAsync[T](IExecutionContext executionContext)

    at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)

    at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)

    at Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync[T](IExecutionContext executionContext)

    at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)

    at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)

    at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)

    at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)

    at Amazon.S3.Internal.AmazonS3ExceptionHandler.InvokeAsync[T](IExecutionContext executionContext)

    at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext)

    at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext)

    at filer_sharing_api.Controllers.BucketController.UploadFileAsync(String bucketName, String objectName, String filePath) in D:\folder\file-sharing-api\Controllers\BucketController.cs:line 57

    at lambda_method5(Closure, Object)

    at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)

    at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)

    at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

    at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)

    at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)

    at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

    at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

    at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)

    at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)

    at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)

    at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)

    at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)

    at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)

    at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

    HEADERS

    =======

    Accept: text/plain

    Connection: keep-alive

    Host: localhost:5221

    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:125.0) Gecko/20100101 Firefox/125.0

    Accept-Encoding: gzip, deflate, br

    Accept-Language: en-US,en;q=0.5

    Origin: localhost:5221

    Referer: localhost:5221/swagger/index.html

    Content-Length: 0

    Sec-Fetch-Dest: empty

    Sec-Fetch-Mode: cors

    Sec-Fetch-Site: same-origin
    Написано