Get progress of my upload with Imgur.net nuget

LucculLuccul FRMember ✭✭

Hey

I use this nuget imgurapi.readthedocs.io/en/latest/ to upload my image to imgur with Xamarin.Forms.

I want to get my upload progression.

This is my code :

public async Task UploadImage(Stream source)
{
    var client = new ImgurClient(ConstantKeys.ImgurClientId, ConstantKeys.ImgurClientSecret);
    var endpoint = new ImageEndpoint(client);

    try
    {
        var image = await endpoint.UploadImageStreamAsync(source);  

        var link = image.Link;
        ImageLink = link;
        _clipboardService.CopyToClipboard(link);
    }
    catch (Exception ex)
    {
        Debug.WriteLine(@"/!\ DEBUG - UploadImage method : " + ex.Message);
    }
}

The owner link me this tutorial, but i never worked with Progress, and i need help:
https://blogs.msdn.microsoft.com/dotnet/2012/06/06/async-in-4-5-enabling-progress-and-cancellation-in-async-apis/

Any suggestion ?

Thank you

Best Answer

Answers

  • JulienRosenJulienRosen CAMember ✭✭✭✭

    you would need endpoint.UploadImageStreamAsync to be able to report its progress back to you so you can display it. doesn't look like this is the case.

  • LucculLuccul FRMember ✭✭
    edited May 2016

    Yes and i don't find how i can do that.

    I try to create my own uploader, but i have this issue: Uri is longer than the maximum 32766 characters

    private string ImageToBase64(Stream stream)
            {
                var memoryStream = new MemoryStream();
                stream.CopyTo(memoryStream);
                var result = memoryStream.ToArray(); 
    
                var base64img = Convert.ToBase64String(result);
    
                StringBuilder sb = new StringBuilder();
    
                for (int i = 0; i < base64img.Length; i += 32766)
                {
                    sb.Append(Uri.EscapeDataString(base64img.Substring(i, Math.Min(32766, base64img.Length - i))));
                }
    
                return sb.ToString();
            }
    
  • JulienRosenJulienRosen CAMember ✭✭✭✭

    i doubt the imgur api expects images in base64 on the url

Sign In or Register to comment.