Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7495371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:04:08+00:00 2026-05-29T18:04:08+00:00

I am using imgur API to upload images but i am getting an exception

  • 0

I am using imgur API to upload images but i am getting an exception on this line:

string uploadRequestString = "image=" + Uri.EscapeDataString(Convert.ToBase64String(imageData)) + "&key=" + apiKey;

Invalid URI: The Uri string is too long.

Full code:

public static string PostToImgur(string imagFilePath, string apiKey)
{
    byte[] imageData;
    FileStream fileStream = File.OpenRead(imagFilePath);
    imageData = new byte[fileStream.Length];
    fileStream.Read(imageData, 0, imageData.Length);
    fileStream.Close();

    string uploadRequestString = "image=" + Uri.EscapeDataString(Convert.ToBase64String(imageData)) + "&key=" + apiKey;

    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://api.imgur.com/2/upload");
    webRequest.Method = "POST";
    webRequest.ContentType = "application/x-www-form-urlencoded";
    webRequest.ServicePoint.Expect100Continue = false;

    StreamWriter streamWriter = new StreamWriter(webRequest.GetRequestStream());
    streamWriter.Write(uploadRequestString);
    streamWriter.Close();

    WebResponse response = webRequest.GetResponse();
    Stream responseStream = response.GetResponseStream();
    StreamReader responseReader = new StreamReader(responseStream);

    string responseString = responseReader.ReadToEnd();

    XmlDocument doc = new XmlDocument();
    doc.InnerXml = responseString;
    XmlElement root = doc.DocumentElement;
    responseString = root.GetElementsByTagName("original")[0].InnerText;

    return responseString;
}

It works for smaller size file but getting that error on large files.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T18:04:13+00:00Added an answer on May 29, 2026 at 6:04 pm

    I suspect that the output from System.Convert.ToBase64String(imageData) is too long to be a valid URI which is around 2000 characters (I think it’s 2048).

    This will be related to the size of the image as a smaller image can be encoded into a shorter string.

    You aren’t going to be able to get round this limit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Imgur api to upload image from my webapp. How to extract
I'm using this PHP to parse a XML file: <?php $xml = simplexml_load_file(http://api.imgur.com/2/image/zzFV5.xml); echo
Not sure what would be causing this, but when I upload some images to
Is there any harm hosting images through a website like Imgur then using the
I can't post images yet: https://i.stack.imgur.com/dJio5.jpg Using Actionscript 3 I'm drawing multiple Shapes onto
Hi I'm trying to figure out how to upload to imgur using java, does
using the script code below, this returns the images from facebook vertically. ive removed
I'm currently uploading an image to a server using Imgur on iOS with the
I have images to overlay on google maps by using checkboxes. I made this
Using the google maps API (v3) I can successfully add an array of markers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.