Click here to Skip to main content
16,004,727 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I'm trying to use the url of the image uploaded to the imgur API service so it should look like this:

<img='_imgurl'>

This is the actual code I have, on which it gives me a error 404 or error 401, corresponding to "System.Net.WebException: 'The remote server returned an error: (404) Not found.'"
C#
using (var w = new WebClient())
                {
                    using (var ms = new MemoryStream())
                    {

                        using (var image = Picture.Image)
                        {
                            using (MemoryStream m = new MemoryStream())
                            {
                                image.Save(m, image.RawFormat);
                                byte[] imageBytes = m.ToArray();

                                // Convert byte[] to Base64 String

                                string base64String = Convert.ToBase64String(imageBytes);
                                var values = new NameValueCollection
                                {
                                    { "key", "2781d465a48c3e2" },
                                    { "image", Convert.ToBase64String(imageBytes) }
                                };
                                byte[] response = w.UploadValues("https://api.imgur.com/3/upload", values);

                                var responseXml = XDocument.Load(new MemoryStream(response));
                                _imgurl = (string)responseXml.Root.Element("link");
                            }
                        }
                    }     
                }


What I have tried:

Changing the url and the key from client_key to secret_key
Tried the solution provided.
Tried to use the variety of links and diferent keys.(Gives me (401) error: Not authorized)
Posted
Updated 6-Jun-17 0:17am
v3
Comments
F-ES Sitecore 5-Jun-17 9:08am    
For a start according to the documentation you are using the wrong endpoints.
Scribling Doodle 5-Jun-17 9:15am    
And what does that mean exactly? Should I change the element to another thing?

1 solution

The upload endpoint is either https://imgur.com/api/3/upload or https://imgur.com/api/3/image. Definitely not http://imgur.com/api/3/upload.xml
Also check this: Imgur.API — Imgur.API 3.7.0 documentation[^]
It may help you...
 
Share this answer
 
v2
Comments
Scribling Doodle 5-Jun-17 9:26am    
Both of them does not work, seems to give the same error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900