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