0

How do you send images from a mobile web app to an existing web service. I considered using the PhoneGap FileTransfer object, but I don't know how to wrap the call in a SOAP packet.

The server where I need to upload the image, expects the image to wrapped in a SOAP packet. From the service description below, one can see that the server expects the file in base64Binary. Has anyone done something like this before, or am I the first (or last) buffalo to cross the river (to get eaten by a crocodile):

POST /Service.asmx HTTP/1.1
Host: 127.0.0.1
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Header>
    <AuthHeader xmlns="http://localhost/">
      <LogonID>string</LogonID>
      <Password>string</Password>
    </AuthHeader>
  </soap12:Header>
  <soap12:Body>
    <uploadFile xmlns="http://localhost/">
      <FileDetails>
        <ReferenceNumber>string</ReferenceNumber>
        <FileName>string</FileName>
        <FileType>int</FileType>
        <FileContents>base64Binary</FileContents>
      </FileDetails>
    </uploadFile>
  </soap12:Body>
</soap12:Envelope>
Jack
  • 16,506
  • 19
  • 100
  • 167

3 Answers3

1

You can have a look here on how to call SOAP webservices from javascript. and here for base64 encoding files

Manatok
  • 5,506
  • 3
  • 23
  • 32
  • 1
    That's really a great answer, have you ever tried sending a SOAP request with mtom attachment using javascript? – ye9ane Jan 08 '13 at 12:03
0

May not be the direct solution as you are looking for but following example might work for you.

http://www.javascriptbank.com/javascript/article/ajax/simple-ajax-file-uploader/preview/en/

Also this SOW thread has list of alternatives to call webservice from javascript.

Simplest SOAP example

Community
  • 1
  • 1
dhaval
  • 7,611
  • 3
  • 29
  • 38
0

I gave up on trying to upload an image directly from JavaScript to a SOAP web service - it was becoming too much of a hack.

I solved the problem by developing gateway to act as a filter between the mobile app and the web service. The gateway filters out image upload requests and extracts the base64 encoded image sent by a PhoneGap FileTransfer object. It then converts this into a base64binary array as expected by the web service.

It is just much more flexible this way, than to try and do everything in JavaScript.

Jack
  • 16,506
  • 19
  • 100
  • 167