Binary multipart upload by HTTP POST to web service

Discussion in 'Questions (Windows Mobile)' started by bluedude, Mar 4, 2009.

  1. bluedude

    bluedude Well-Known Member Licensed User

    I have a simple idea but i'm not sure how to code it. I want an image captured by the camera uploaded by HTTP to a web service.

    Anyone any ideas on how to do this? The image should be uploaded binary.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    There is an example in the manual that uses the HTTP PUT method to upload a binary file: HTTP
    I guess that it shouldn't be too difficult to convert it to use POST method instead (you will need to first set the content type and length which you can find with FileSize).
     
  3. bluedude

    bluedude Well-Known Member Licensed User

  4. Erel

    Erel Administrator Staff Member Licensed User

    It will be a little bit more complicated.
    I've found some c# code that deals with this problem: how to upload file via c# code - bytes
    I will convert it to Basic4ppc and upload it tomorrow.
     
  5. bluedude

    bluedude Well-Known Member Licensed User

    Any succes with this?

    Erel,

    Any luck with this?
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    That was a long day ;)
    I've uploaded a small program based on this code: how to upload file via c# code - bytes
    I don't have an account so I get an 'unknown user' error.
    Tell me how it went.
     

    Attached Files:

    • 1.sbp
      File size:
      2.5 KB
      Views:
      150
  7. Aspire89

    Aspire89 Member Licensed User

    Thanks, good example.
    I have an account on this site and tried how it works. In response, I receive an error:

    <? xml version = "1.0" encoding = "UTF-8"?>
    <rsp stat="fail">
    <err Code="1002" msg="Image not found" />
    </ rsp>


    The path to the file checked, all OK.
    Then he looked at his request in HttpAnalizer. Although the method is POST, and POST data is empty, and the username and password into the stream.
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    It did send the data using POST. I'm sorry but I don't know what is the problem.
     
  9. Aspire89

    Aspire89 Member Licensed User

    I used the following code:

    Code:
    request.New1("http://tweeterwall.mallplace.com/tw/vote")
        request.Method = 
    "POST"
        request.UserAgent = 
    "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.1.1) Gecko/20090715 MRA 5.3 (build 02560) Firefox/3.5.1 (.NET CLR 3.5.30729)"    
        Request.ContentType = 
    "text/javascript"
        stream.New1(Request.GetStream,
    False
        name = 
    "uid=27024&country_id=68&token=049226fb46577eb02790105aae66dc1e"
        stream.WriteBytes(stream.StringToBytes(name))
        response.New1
        request.GetAsyncResponse
    and HttpAnalizer received the following (details in the screenshot)
     
  10. Aspire89

    Aspire89 Member Licensed User

  11. bluedude

    bluedude Well-Known Member Licensed User

    Problem too

    Hi Erel,

    First let me say that you are very quick in replies etc! You do a great job running this forum and software.

    The multipart post solution for Twipic does not work for me, same problem as the other user.

    What i'm basically looking for is a generic sample that combines posting fields and a file in one call. Im working on a product that can talk to a whole bunch of web services (POST) and this binary upload stuff frustrates me.

    For some services i write my own small PHP wrappers to make it easier but the uploading stuff in combination with input fields I cannot get to run.

    This sample has a lot of stuff I don't understand (boundary).

    Hope you have a generic sample and maybe even better with Async stuff.
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    I'm sorry but I'm not an expert in this field too.
    I did my best to convert this c# code into Basic4ppc.
     
  13. bluedude

    bluedude Well-Known Member Licensed User

    Understood

    Ok, that is understood.

    Need to figure out how to do it in BASIC4PPC. Posting data is simple but not sure how to combine file and input fields.
     
  14. bluedude

    bluedude Well-Known Member Licensed User

    Multipart upload

    Erel,

    This multipart stuff is killing me, there are so many projects where you need HTTP upload to create interesting applications.

    Here is s simpler sample in VB: Sample Visual Basic Examples by Conor Hackett - TweetPhoto Developers | Google Groups

    Has anyone solved this in the end?

    Is there anyone who has time to develop a dll for this? I think a generic multipart upload dll would be awesome.

    Without it we are very limited regarding file operations, FTP is not really an option because none of these web services support FTP.

    Any help is appreciated, i'm even prepared to pay for it!!!
     
  15. TWELVE

    TWELVE Active Member Licensed User

    I can help out here, had the same issue with the POST multipart, after some intense network tracing, comparing and reading a couple of RFCs i finally got it to work.

    I will post example code here soon, once i've tested everything...


    regards,

    TWELVE
     
  16. a6000000

    a6000000 Member Licensed User

    Please can anyone post how to find the last Picture from camera to upload?
    [EDIT] find: http://www.basic4ppc.com/forum/code...e-using-internal-camera-your-application.html [/EDIT]

    BUT: to send a binary file-stream (picture) , for send over HTTP-POST works
    '// ( no more problems with PUT -the samples here I do not bring to work)
    when I convert it to ascii - I convert it to longer stream , and ONLY USE PRINTABLE chars
    (I was inspirated by JSON ) and tested til 2Megabyte Pictures on desktop , now I will try on my ppc .
    in the web I reconvert the POST to binary with php.

    :cool:
     
    Last edited: Jun 28, 2010
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice