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

Fix Uploading QR Codes #237

Closed
wants to merge 1 commit into from
Closed

Fix Uploading QR Codes #237

wants to merge 1 commit into from

Conversation

ashkanRmk
Copy link

When you generate QR Code and want to upload it to storage, it uploaded with zero length.

with this method, you can convert stream to byte array easily with any kind of stream generator.

@@ -842,33 +842,13 @@ public async Task<ObjectStat> StatObjectAsync(string bucketName, string objectNa
/// <returns>bytes read in a byte array</returns>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic of currentPartSize is totally ignored here @Ashkan-rmk you need to see the flow why ReadFull() is implemented. It is to upload large files with an optimal part size. Your code simply loads everything into memory it will crash the program.

What you need to do is simply provide the stream and with putObjectAsync taking in -1 for length as the input parameter.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use QR code generator nuget package. It generate a memory stream object and when I pass it to putObjectAsync it uploaded with 0 byte!

you mean that I have to pass "-1" as a parameter to putObjectAsync?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's correct. pass size as -1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pass size as -1 but it returns

The XML you provided was not well-formed or did not validate against our published schema.

what should I do?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really need this, and block our work...
I'd appreciate you to help.
what should I do?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    public static void Main(string[] args)
    {
        string accessKey = "xxxx";
        string secretKey = "xxxxxxxxx";
        string ServiceURL = "miniostage.sloppy.zone";

        client = new MinioClient(ServiceURL, accessKey, secretKey).WithSSL();

        try
        {
            UploadImageAsync().Wait();
        }
        catch (Exception ex)
        {
            Console.WriteLine($"There was an exception: {ex.ToString()}");
        }

    }

    public static async Task UploadImageAsync()
    {
        string bucketName = "files";

        var qr_code = PayPing.Common.Tools.QrCodeGeneratorHelper.GenerateUrl("https://payping.ir/d/352", true, false);
        var extension = qr_code.imageFormat.GetImageFileExtension().Replace(".", "");

        string keyName = $"QRTest23.{extension}";

        await client.PutObjectAsync(
                  bucketName,
                  keyName,
                  qr_code.stream,
                  -1,
                  "application/octet-stream");

        Console.WriteLine(keyName);
    }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the QR Code successsfuly generate stream.
as you said I pass -1 as parameter to PutObjectAsync, but it throw this exception.

The XML you provided was not well-formed or did not validate against our published schema.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ashkan-rmk I replaced the QR code generation with a simple Byte array based MemoryStream with rest of the program as is. I don't see the above exception and the object is uploaded successfully. Could you come on https://slack.minio.io/? It would be easier to resolve the issue over slack.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ashkan-rmk, would suggest copying your stream to a memory stream and pass size as -1 for the PutObjectAsync call.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I came to Slack channel... thanks.

@ashkanRmk ashkanRmk closed this Aug 14, 2018
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

Successfully merging this pull request may close these issues.

None yet

4 participants