Quantcast
Channel: SCN: Message List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 9165

Re: Using XS to upload a binary file?

$
0
0

Hi,

 

I had tried that before...or at least thought I did.  I wanted to respond with the error, so I went back and executed that version of code and got the exception:

$.request.entities[i].body.asBufferArray is not a function

 

Then it hit me what I did wrong.  I used the function asBufferArray rather than asArrayBuffer,  Agggh!!!  How many hours were wasted because of a stupid typo.

 

Anyways, here is the corrected code:

 

function isFileUploaderEntity(entity) {          if (entity.headers) {                    var i;                    for (i = 0; i < entity.headers.length; i++) {                              if (entity.headers[i].name && (entity.headers[i].name === "~content_name") && (entity.headers[i].value === "fileUploader")) {                                        return true;                              }                    }          }          return false;
}

function getFile() {
          var file = {};          try {                    var contents = null;                    var type = "";                    var i;                    for (i = 0; i < $.request.entities.length; i++) {                              if (isFileUploaderEntity($.request.entities[i])) {                                        type = $.request.entities[i].contentType;                                        contents = $.request.entities[i].body.asArrayBuffer();                                        break;                              }                    }                      file.type = type;                    file.contents = contents;          } catch (e) {                    throw "Failed to upload file: EXCEPTION=" + e.message;          }          return file;
}

 

The code is designed to work in conjection with a file sent from a client using the SAPUI5 FileUploader.

 

Regards,

David


Viewing all articles
Browse latest Browse all 9165

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>