1

Does anybody know how to upload to imageshack.us with C#? Two other threads here couldn't help:/ That's my piece of code. "PostParamCollection" is a library for sending HTTP Post. Lots of thanks for any help!

Im getting the error-message: " Sorry, but we've detected that unexpected data is received. Required parameter 'fileupload' is missing or your post is not multipart/form-data "

String imageshackurl = "http://www.imageshack.us/upload_api.php?";

                    PostParamCollection postParamCollection = new PostParamCollection();
                    postParamCollection.Add(new PostParam("key", imageshack_key));
                    postParamCollection.Add(new PostParam("Content-Disposition", "form-data"));
                    postParamCollection.Add(new PostParam("filename", "a.jpg"));
                    postParamCollection.Add(new PostParam("Content-Type", "image/png"));

                    HttpPost httpPost = new HttpPost(imageshackurl);
                    httpPost.doPost(postParamCollection);
                    String link = httpPost.responseStream;

                    WriteLog(link);
DanM7
  • 2,203
  • 3
  • 28
  • 46
BigX_Jazz
  • 103
  • 3
  • 13
  • this should help you http://stackoverflow.com/questions/3890754/c-using-httpwebrequest-to-post-data-upload-image-using-multipart-form-data – Prabhu Murthy Sep 27 '12 at 11:50

1 Answers1

0

You don't appear to be adding a fileupload parameter to your postParamCollection, which, I assume, would need to be of type byte[] and contain the file's contents.

I see that PostParam uses strings for its name and value, which is unsuitable for submitting binary data, such as an image file. Unfortunately, you will need to use a different method for posting the data to ImageShack. Take a look at the built-in .NET WebClient class, which should allow you to do this.

Ashley Ross
  • 2,345
  • 2
  • 23
  • 43