Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to put an object in s3 #709

Closed
anthonyMc11 opened this issue Nov 8, 2022 · 1 comment
Closed

unable to put an object in s3 #709

anthonyMc11 opened this issue Nov 8, 2022 · 1 comment

Comments

@anthonyMc11
Copy link
Contributor

This issue follows on from my previous issue #673 , its the same code but a different path through to the issue

I am using the following code:

using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Minio;
namespace MinioClientTest
{
    class Program
    {
        static async Task Main()
        {
            var minIoClient = new MinioClient().WithEndpoint("localhost:9000").WithCredentials("LocalaccessKey", "localSecretKey").Build();
            var amazonClient = new MinioClient().WithEndpoint("s3.amazonaws.com").WithCredentials("s3AccessKey", "s3AccessSecret").WithSSL().WithRegion("eu-west-2").Build();
            
            var minIoSourceBucket = "default";
            var minIoSourceFilePath = "SomeLogFile.txt";

            var amazonSinkBucket = "SomeBucket";
            var amazonSinkFilePath = "SomeLogFile.txt";


            var getArgs = new GetObjectArgs().WithBucket(minIoSourceBucket)
                .WithObject(minIoSourceFilePath)
                .WithCallbackStream(async stream =>
                {
                    var memoryStream = new MemoryStream();
                    stream.CopyTo(memoryStream);
                    memoryStream.Seek(0, SeekOrigin.Begin);
                    await PutObjectAsync(amazonClient, amazonSinkBucket, amazonSinkFilePath,
                        memoryStream, memoryStream.Length, "application/octet-stream");
                
                });
            var getResult = await minIoClient.GetObjectAsync(getArgs);
        
            Console.ReadKey();
        }
        public static async Task PutObjectAsync(MinioClient mediaClient, string bucketName, string objectName, Stream data, long size, string contentType = null,
            Dictionary<string, string> metaData = null, CancellationToken cancellationToken = new CancellationToken())
        {
            var obj = new PutObjectArgs()
                .WithBucket(bucketName)
                .WithObject(objectName)
                .WithStreamData(data)
                .WithObjectSize(size);
            if (!string.IsNullOrWhiteSpace(contentType))
            {
                obj.WithContentType(contentType);
            }
            if (!(metaData is null))
            {
                obj.WithHeaders(metaData);
            }
            await mediaClient.PutObjectAsync(obj, cancellationToken);
        }
    }
}

I have diagnosed this to the CreateRequest method, the code does not load the region if it is a PUT request. This was added to prevent createBucket requests from failing however it means the region is not loaded for this put object request

I will raise a PR with my code fix for this

anthonyMc11 pushed a commit to anthonyMc11/minio-dotnet that referenced this issue Nov 8, 2022
anthonyMc11 pushed a commit to anthonyMc11/minio-dotnet that referenced this issue Nov 8, 2022
@ebozduman
Copy link
Collaborator

@anthonyMc11,
I noticed there might be another issue in GetRegion() method, but I will be addressing it in a separate issue, if it turns out to be legit.
Closing this one as fixed by PR #711

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants