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
Conversation
@@ -842,33 +842,13 @@ public async Task<ObjectStat> StatObjectAsync(string bucketName, string objectNa | |||
/// <returns>bytes read in a byte array</returns> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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);
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.