Skip to Content
0
Former Member
May 27, 2015 at 07:11 PM

Execute XSJS service via POST

561 Views

Hello All,

I'm newbie on SAP UI5 development and currently facing a problem.

I'm trying to import a file using File Uploader component and so far, i have set a XSJS to call a REST service to handle the file uploaded.

So i did,

My View:

<FileUploader

id="fileUploader"

name="myFileUpload"

uploadOnChange="false"

uploadUrl="../WebContent/service/fileImport.xsjs?cmd=inserir"

width="400px"

tooltip="Upload your file to the local server"

/>

Controller:

onImport : function(){

var oFileUploader = this.getView().byId("fileUploader");

oFileUploader.upload();

}

XSJS file (only test content, i'll have to change this when uploading):

function inserir() {

var body = "test";

$.response.setBody(body);

$.response.contentType = "text/plain";

$.response.status = $.net.http.OK;

}

var acmd = $.request.parameters.get("cmd");

switch (acmd) {

case "inserir":inserir();break;

default:

$.response.status = $.net.http.OK;

$.response.setBody("inavalid: "+acmd);

}

However, when i run this code, select some file and click at the button, i receive:

http://HOST:PORT/PROJECT/WebContent/service/fileImport.xsjs?cmd=inserir 403 (Forbidden)

I really don't know why i'm getting a forbidden access to this. If i use some rest plugin, like Advanced Rest Client (Chrome) i also receive this FORBIDDEN error. Although, when i choose POST and call this XSJS directly on the browser (GET) or via GET in Advanced Rest Service i'm able to execute correctly.

So, my problem is execute this XSJS via POST.

Can anyone help me out? Is there some step missing?

Thanks in Advance

Best Regards