Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Upload GIF File #1

Closed
VollRahm opened this issue May 1, 2019 · 3 comments
Closed

Upload GIF File #1

VollRahm opened this issue May 1, 2019 · 3 comments

Comments

@VollRahm
Copy link

VollRahm commented May 1, 2019

When i try to upload i GIF File i get following exception:
System.UriFormatException: Invalid URI: The uri string is too long

@VollRahm
Copy link
Author

VollRahm commented May 1, 2019

I worked a bit on the problem.
The problem was that a url can only hold 2083 letters and the Base64 string was too long.
I fixed it by Sending it as JSON.
You need to replace this in public async Task<ImgurImage> UploadImageAnonymous(Stream imageStream, string name, string title, string description):

using (HttpClient client = new HttpClient())
            {
                SetHeaders(client);

                string base64Image = PhotoStreamToBase64(imageStream);
                
                var formContent = new FormUrlEncodedContent(new[] { 
                    new KeyValuePair<string, string>("image", base64Image),
                    new KeyValuePair<string, string>("name", name),
                    new KeyValuePair<string, string>("title", title),
                    new KeyValuePair<string, string>("description", description)
                });

                
                HttpResponseMessage response = await client.PostAsync(new Uri(BaseUrl + "upload"), formContent);

by this:

public async Task<ImgurImage> UploadImageAnonymous(Stream imageStream, string _name, string _title, string _description)
        {
 using (HttpClient client = new HttpClient())
            {
                SetHeaders(client);

                string base64Image = PhotoStreamToBase64(imageStream);

                var options = new
                {
                    image = base64Image,
                    name = _name,
                    title = _title,
                    description = _description
                };

                var jsonData = JsonConvert.SerializeObject(options);
                var formContent = new StringContent(jsonData, Encoding.UTF8, "application/json");
                
                HttpResponseMessage response = await client.PostAsync(new Uri(BaseUrl + "upload"), formContent);

@Auo
Copy link
Owner

Auo commented May 2, 2019

Hi!
Thank for using the lib, and for your debugging!
Feel free to create a pull-request!

@Auo Auo closed this as completed in aa0333b May 2, 2019
@Auo
Copy link
Owner

Auo commented May 2, 2019

I couldn't resist fixing it!

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

No branches or pull requests

2 participants