iOS Question HTTPUTILS2 Error 500

Discussion in 'iOS Questions' started by Indy, Jul 12, 2015.

  1. Indy

    Indy Member Licensed User

    Hi Erel,

    When posting the string, is there a limit to the size of the string? I get an error when trying to upload a ~300K jpg file. I'm encoding the bytes to 64 bits. If I post a small file 1 or 2k it works fine. Problem when I try to view the string in the log file is the post string gets truncated so I cannot see the entire sent http post.

    I used the equivalent version of this library in my Android project and that works ok with jpgs. I'm now converting my app to iOS but stuck on this final bit. The code I'm using is pretty much the code you have in your example. What I can't do is show the actual post string as it's being truncated and besides it's just be a load of hex code.

    Thanks
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Are you sending the image inside the url? Or as a POST payload (much better)?
     
  3. Indy

    Indy Member Licensed User

    Hi Erel,

    I use the HTTP upload as follows;

    Code:
    Dim Job5b As HttpJob
    Dim strFilterXML As String = "<soap:Body><UploadData xmlns=""http://web.xxxxx.xxxx.xxxxx/""><f>" & su.EncodeBase64(ReadFile(Main.ImagesDir,UploadFL.Get(UploadFL.Size-1))) & "</f><fn>" & UploadFL.Get(UploadFL.Size-1) & "</fn><DID>" & Main.DID & "</DID></UploadData></soap:Body>"

    Job5b.Initialize(
    "Job5b", Me)
    Job5b.PostString(
    "http://web.xxxxx.xxxx.xxxxx/webservice.asmx", XML.Replace("<soap:Body />", strFilterXML))   
    Job5b.GetRequest.SetHeader(
    "SOAPAction""http://web.xxxxx.xxxx.xxxxx/UploadData")     
    Job5b.GetRequest.SetHeader(
    "Content-Type""text/xml; charset=utf-8")
    The above code works absolutely fine when uploading a small file. But as soon as I use a image file ~300kb the upload fails. FYI - I have exactly the same code in the Android version and that doesn't fail, although I must admit the image files are smaller because the resize function used seems to work better.

    Can you see if there's anything I'm doing wrong?

    Thanks
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Please try the following steps:

    1. In your Android project create the payload string and save it to a text file in File.DirRootExternal (with File.WriteString).
    2. Copy the file to the pc and add it to the B4i project.
    3. Use File.ReadString to read the file and use this text as the request payload.
     
  5. Indy

    Indy Member Licensed User

    Hi Erel,

    Thanks for your suggestion, which I will try. However, just as a test I exported the string to a text file anyway just to see if it was complete, which it was. So, wouldn't reading it in and sending it have the same effect I'm having now? Or is it File.Readstring different? I'm getting the feeling the string is too long. What do you think?

    Thanks
     
  6. Indy

    Indy Member Licensed User

    Hi Erel,

    Just as I suspected, using File.Readstring produced the same error. I definitely think string is too large for the message. The image is only 1024x768 but at ~300kb maybe it's just pipped past the max allowed message size.

    I'm going to try the Android version again and save the string to a file and see how that compares and update you.

    Thanks
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    It is worth testing it. Maybe the problem is in the base 64 encoding. If you like send me the code and I'll try it.
     
Loading...