Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Sending an Image over HTTP.

Sending an Image over HTTP.

Scheduled Pinned Locked Moved C#
csharpphpcomsysadmintutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jon Newman
    wrote on last edited by
    #1

    Here's a puzzle. I intend to send an image (jpeg) to a PHP-Driven website via HTTP POST, using a C# app compiled for the .NET Compact Framework. So far Its all working apart from one thing, when sending the file, it is created on the server, but is corrupt. I'm positive this is down to the image not being sent in the correct format, but what format is it supposed to be sent? The method of sending is using a WebRequest object and its RequestStream. Method = "POST"; ContentType = "multipart/form-data; boundary=AaB03x"; The following HTTP post is sent through the stream.

    --AaB03x
    Content-Disposition: form-data; name="title"
    Content-Type: text/plain; charset=utf-8

    Title

    --AaB03x
    Content-Disposition: attachment; name="file" filename="nexi0001.jpg"
    Content-Type: image/jpeg
    Content-Transfer-Encoding: binary

    contents of file...
    --AaB03x--

    Now alls I need to do is send the image data with this. Yet I've no idea in what format to send it and thus how to prepare this format on the CF. Ideas?


    Jonathan 'nonny' Newman blog.nonny.com [^]

    M N 2 Replies Last reply
    0
    • J Jon Newman

      Here's a puzzle. I intend to send an image (jpeg) to a PHP-Driven website via HTTP POST, using a C# app compiled for the .NET Compact Framework. So far Its all working apart from one thing, when sending the file, it is created on the server, but is corrupt. I'm positive this is down to the image not being sent in the correct format, but what format is it supposed to be sent? The method of sending is using a WebRequest object and its RequestStream. Method = "POST"; ContentType = "multipart/form-data; boundary=AaB03x"; The following HTTP post is sent through the stream.

      --AaB03x
      Content-Disposition: form-data; name="title"
      Content-Type: text/plain; charset=utf-8

      Title

      --AaB03x
      Content-Disposition: attachment; name="file" filename="nexi0001.jpg"
      Content-Type: image/jpeg
      Content-Transfer-Encoding: binary

      contents of file...
      --AaB03x--

      Now alls I need to do is send the image data with this. Yet I've no idea in what format to send it and thus how to prepare this format on the CF. Ideas?


      Jonathan 'nonny' Newman blog.nonny.com [^]

      M Offline
      M Offline
      Mazdak
      wrote on last edited by
      #2

      I think you have to send it in Base64 format. For the beginning check ToBase64Transform class. Mazy "Improvisation is the touchstone of wit." - Molière

      J 1 Reply Last reply
      0
      • M Mazdak

        I think you have to send it in Base64 format. For the beginning check ToBase64Transform class. Mazy "Improvisation is the touchstone of wit." - Molière

        J Offline
        J Offline
        Jon Newman
        wrote on last edited by
        #3

        I can't seem to be able to use that class in the Compact Framework, would Convert.ToBase64CharArray() work do you think?


        Jonathan 'nonny' Newman blog.nonny.com [^]

        M 1 Reply Last reply
        0
        • J Jon Newman

          I can't seem to be able to use that class in the Compact Framework, would Convert.ToBase64CharArray() work do you think?


          Jonathan 'nonny' Newman blog.nonny.com [^]

          M Offline
          M Offline
          Mazdak
          wrote on last edited by
          #4

          Jonny Newman wrote: would Convert.ToBase64CharArray() work do you think? I think no problem with that. You have to tranform to base64. No matter with which function. :) Mazy "Improvisation is the touchstone of wit." - Molière

          1 Reply Last reply
          0
          • J Jon Newman

            Here's a puzzle. I intend to send an image (jpeg) to a PHP-Driven website via HTTP POST, using a C# app compiled for the .NET Compact Framework. So far Its all working apart from one thing, when sending the file, it is created on the server, but is corrupt. I'm positive this is down to the image not being sent in the correct format, but what format is it supposed to be sent? The method of sending is using a WebRequest object and its RequestStream. Method = "POST"; ContentType = "multipart/form-data; boundary=AaB03x"; The following HTTP post is sent through the stream.

            --AaB03x
            Content-Disposition: form-data; name="title"
            Content-Type: text/plain; charset=utf-8

            Title

            --AaB03x
            Content-Disposition: attachment; name="file" filename="nexi0001.jpg"
            Content-Type: image/jpeg
            Content-Transfer-Encoding: binary

            contents of file...
            --AaB03x--

            Now alls I need to do is send the image data with this. Yet I've no idea in what format to send it and thus how to prepare this format on the CF. Ideas?


            Jonathan 'nonny' Newman blog.nonny.com [^]

            N Offline
            N Offline
            Not Active
            wrote on last edited by
            #5

            Is System.Net.WebClient.UploadFile method available in CF?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups