5 Replies - 1294 Views - Last Post: 11 January 2012 - 07:25 PM Rate Topic: -----

#1 acll19  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 63
  • Joined: 20-October 10

uploading an image with HttpWebRequest

Posted 10 January 2012 - 11:46 PM

Hi there, I'm making a software that fills out a form(from a web site). I'm using an HttpWebRequest and there's no trouble with that. The thing is that the form has an image field and I don't know how to sent that image. I did some googling and I came up with this;
 
System.Drawing.Image s = System.Drawing.Image.FromFile(announcement.Images[i]);

string base64Image;
using (MemoryStream ms = new MemoryStream())
{
s.Save(ms, ImageFormat.Jpeg);

 base64Image = Convert.ToBase64String(ms.ToArray());



but this doesn´t work.
i would appreciate any help.

Is This A Good Question/Topic? 1
  • +

Replies To: uploading an image with HttpWebRequest

#2 pryogene  Icon User is offline

  • The Leafiest of the Leif's
  • member icon

Reputation: 42
  • View blog
  • Posts: 673
  • Joined: 30-June 09

Re: uploading an image with HttpWebRequest

Posted 11 January 2012 - 05:59 AM

View Postacll19, on 10 January 2012 - 11:46 PM, said:

Hi there, I'm making a software that fills out a form(from a web site). I'm using an HttpWebRequest and there's no trouble with that. The thing is that the form has an image field and I don't know how to sent that image. I did some googling and I came up with this;
 
System.Drawing.Image s = System.Drawing.Image.FromFile(announcement.Images[i]);

string base64Image;
using (MemoryStream ms = new MemoryStream())
{
s.Save(ms, ImageFormat.Jpeg);

 base64Image = Convert.ToBase64String(ms.ToArray());



but this doesn´t work.
i would appreciate any help.


All of your code would be useful. What exactly is your problem? It looks like you're trying to save it to your own computer, not an upload stream. If I were to go out on a limb, I'd say it would be the same...
Was This Post Helpful? 0
  • +
  • -

#3 cilaes  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 75
  • Joined: 12-December 11

Re: uploading an image with HttpWebRequest

Posted 11 January 2012 - 11:40 AM

From what I've read, it's more optimal to
1) Create HttpWebRequest
2) Create MemoryStream
3) Read file into MemoryStream through FileStream
4) Write to the request stream.

This post has been edited by cilaes: 11 January 2012 - 11:49 AM

Was This Post Helpful? 0
  • +
  • -

#4 acll19  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 63
  • Joined: 20-October 10

Re: uploading an image with HttpWebRequest

Posted 11 January 2012 - 01:53 PM

do I have to tell the request that I'm writing an image into it?
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: uploading an image with HttpWebRequest

Posted 11 January 2012 - 01:55 PM

Did you happen to find this when you were searching for how to do this?
Was This Post Helpful? 0
  • +
  • -

#6 acll19  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 63
  • Joined: 20-October 10

Re: uploading an image with HttpWebRequest

Posted 11 January 2012 - 07:25 PM

Thanks man you saved my day. I guess I gotta learn to search the net, laughing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1