2

I'm trying to build JPG upload functionality into our Windows Phone app.

The server-side is complete; I have a REST API already built that accepts a standard JPG via HTTP POST and saves it to the server. I can successfully post to this from a FORM in html.

However, after two days of trying various approaches, I still cannot figure out how to craft the C# code that builds this HTTP POST using either HttpWebRequest or WebClient. (Note, while I like WCF, and know it can do REST, I would prefer not to use WCF on the server for consistency's sake with other code.)

I would love to see how to generate a fully compliant HTTP POST, complete with JPG writing, posting up something that can be read by Request.Files[] on the server. I'd post what I've tried, but I think it'd only add to the confusion -- frankly, it's kind of a mess at this stage, and I'm sure the solution is simpler.

I have seen various threads here on StackOverflow and other sites discussing general approaches, but despite these helpful responses, they are incomplete, or not applicable to the WinPhone subset. (Note that UploadFile is not available in the Windows Phone subset of Silverlight, for instance.)

Among other things, I haven't figured out how to convert a JPG to a byte array to write on the stream. Can anyone help me with a fully working code sample of a client sending up a single JPG in an HTTP POST?

Matt Lacey
  • 65,560
  • 11
  • 91
  • 143
user61307
  • 195
  • 2
  • 14

2 Answers2

0

The easiest solution I've found is to use the Windows Phone POST client

Dare Obasanjo
  • 695
  • 10
  • 6
-3

You can find solutions to this at:

Uploading an image using C# and WebRequest?
and
Upload files with HTTPWebrequest (multipart/form-data)

Community
  • 1
  • 1
Matt Lacey
  • 65,560
  • 11
  • 91
  • 143
  • 2
    This is not helpful as those answers are about regular .Net and not Silverlight. – Juliana Peña Mar 24 '11 at 18:21
  • What specifically is the problme with those links? The technique is the same even in Silverlight. – Matt Lacey Nov 30 '11 at 15:59
  • Silverlight is asynchronous only and those solutions only show synchronous code. – Juliana Peña Nov 30 '11 at 22:53
  • The priniciple is the same though. you format the content and POSt it to the webserver. Whether the method you call on the webclient returns synchronously or via a callback doesn't affect the way yuou format and send the data. – Matt Lacey Dec 01 '11 at 18:42