Skip to Content

SAP Mobile Documents delivers not only several clients and a server component, but also an SDK that allows you to develop your own client. Some time ago, I wrote a blog about the development of a custom iOS client. See here:

How to Develop a Custom iOS Client for SAP Mobile Documents

I would like to make you aware of my two brand new how-to guides that have just been published on SCN. The guides show the development of a custom Java client and a custom Java Script client. I explain in detail what you have to do and what you have to be aware of when creating your own client, including prerequisites and necessary settings. You can even download sample code from within the guides.

So check out the following two new how-to guides:

Developing a Custom Java Client for SAP Mobile Documents

Developing a Custom JavaScript Client for SAP Mobile Documents

Regards,

Simon Oehm

To report this post you need to login first.

7 Comments

You must be Logged on to comment or reply to a post.

  1. Christian Schäfer

    Hi Simon,

    Thanks for your guide on developing a custom javascript client – that really helped me getting started!

    My question is, are there or have you any examples on uploading a existing file or picture from a mobile device? I have a JavaScript application and try to upload a picture via an ajax call and can’t get it to work.

    Regards,

    Christian Schäfer

    (0) 
    1. Simon Oehm Post author

      Hi Christian,

      as stated in the official CMIS specification you have to perform a HTTP multipart form request:

      Browser applications typically use HTTP multipart forms as described in [RFC2388] to create and update content.

      This is especially useful for updating file content with the addition of the FILE attribute in [RFC1867].

      In this binding, HTTP POST of multipart/form-data MUST be used to update content streams.

      The specification is a really good resource and also explains how to execute cmis operations via browser binding.

      A typical upload to SAP Mobile Documents might look like the following coding (will not work in old browsers like IE9 because there is no file api):

            var repositoryConnection = repositoryService.

                                                     getMyDocumentsRepositoryConnection(),

                 uploadURL = repositoryConnection.getRootFolderUrl() + ‘?x-token=’ +

                                     repositoryConnection.getCsrfToken()

        jQuery.ajax({

                      type: “POST”,

                      url: encodeURI(uploadURL),               

                      data: createRequestData(),

                      processData: false,

                      contentType: false,               

                  }).done(function(data) { // upload successful}).fail(function(error) { // upload failed});

        

        function createRequestData() {

                  var formData = new FormData(), i;

                  formData.append(“objectid”, parentFolderId);

                  formData.append(“cmisaction”, “createDocument”);

                  formData.append(“propertyId[0]”, “cmis:name”);

                  formData.append(“propertyValue[0]”, fileName);

                  formData.append(“propertyId[1]”, “cmis:objectTypeId”);

                  formData.append(“propertyValue[1]”, objectTypeId);

                  formData.append(“_charset_”, “UTF-8”);

                  formData.append(“media”, file); // this is the content stream of the document (a                                                              file object created with the JavaScript file api)

                  // add additional properties to the document

                  for (i = 0; i < properties.length; i += 1) {

                      formData.append(“propertyId[” + (i + 2) + “]”, properties[i].getName());

                      formData.append(“propertyValue[” + (i + 2) + “]”, properties[i].getValue());

                  }

                  return formData;

              }

      Regarding the usage of the file api have a look here: Using files from web applications | MDN

      Good luck!

      Best Regards,

      Simon

      (0) 
      1. Christian Schäfer

        Thank you for the fast and really detailed answer!

        Nevertheless I don’t get it to work. I’m getting my picture’s data via .readAsBinaryString(file) and append the result to the formData with the key “media” just like you did. When the request is send, my app shows some network traffic and it takes about half a minute (for a 1.2 MB .jpg) before i get into the .done() callback. A file with my given name is created on the server, but with a size of 0KB, that I can’t open or download at all. It seems like the data is sent, but the server can’t process it properly. Any idea on that?

        Thank you in advance, Regards

        Christian

        (0) 
        1. Simon Oehm Post author

          Hi Christian,

          glad to hear that you are at least able to create a document in mobile docs. This means that your request should be fine.

          Maybe you can try to create a fake blob that just contains a string in order to test if the upload works properly:

          var text = “test string”,

               blob = new Blob([text]),

               newBlob = blob.slice(0, blob.size, “text/plain”);

          formData.append(“media”, newBlob);


          If this works then you definitely have an issue with your file object.


          Best Regards,

          Simon

          (0) 
          1. Christian Schäfer

            Got it working by now!

            First I tried creating a text file like you proposed, which worked without a problem. But I had indeed a problem with my file object – I had to convert my base64 string to an Uint8Array before sending it to the server to make it work.

            Thank you very much!!

            Best Regards,

            Christian

            (0) 
  2. John Whelan

    Hi Simon,

    I followed the guide for setting up a Java Client for SAP mobile documents.

    However, I’m getting an CMISConnectionException error: Unable to tunnel through proxy. Proxy returns “HTTP/1.1 403 Forbidden”.

    I am using my hanatrial.ondemand.com as the Mobile Documents server.

    When I don’t set the proxy server settings, I get an unknown host exception.

    Any ideas how I can overcome this problem?

    Thanks,

    John

    (0) 
    1. Peter Sutter

      Hi John,

      do you face the same issue in the SAP Mobile Documents desktop client when specifying the same proxy parameters (using manual proxy) as in your java client?

      Best regards,

      Peter

      (0) 

Leave a Reply