on 05-27-2015 8:11 PM
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
Right!!! Like i said, i'm new at this.
Do you have any suggestion how can i send this file uploaded to a rest call?
Thank in Advance, appreciate your help!!!
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to use the outbound HTTP destination API:
XSJS Outbound Connectivity SPS6 - YouTube
Tutorial: Use the XSJS Outbound API - SAP HANA Developer Guide for SAP HANA Studio - SAP Library
I suspect that you have prevent_xsrf set to true in your xsaccess file. Therefore any non-GET request to a service will require an XSRF token to be sent in the header. You don't have any logic in your client side to request or send this XSRF token. You either need to disable the prevent_xsrf protection or add the XSRF token processing to your request.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Thomas,
Thanks for replying me!!! I figured this out later and i was able to call the XSJS file.
Although i'm facing some more problems with this.
I'm trying to send the file uploaded to a rest service but i still couldn't solve it...
I have a view
<FileUploader
id="fileUploader"
name="myFileUpload"
uploadOnChange="false"
width="400px"
tooltip="Upload your file to the local server"
/>
<Button text="Importar" type="Emphasized" press="onImport" />
controller:
onImport: function(){
var oFileUploader = this.getView().byId("fileUploader");
oFileUploader.setUploadUrl('../WebContent/service/fileImport.xsjs?cmd=uploadFile');
oFileUploader.upload();
}
and the XSJS
function uploadFile() {
$.post("http://localhost:8080/appref/api/20001/gui/excel/test/usu01", function(data) {
$.response.setBody(data);
});
}
var acmd = $.request.parameters.get("cmd");
switch (acmd) {
case "uploadFile":
uploadFile();
break;
default:
$.response.status = $.net.http.OK;
$.response.setBody("comando invalido: " + acmd);
}
but when i ran, i got:
om/prj/b1h/excel/WebContent/service/fileImport.xsjs?cmd=uploadFile 500 (Internal Server Error)
i really dont know why i'm getting this error. I do know that there is something wrong, but i don't know what. I looked up for some documents, but i didn't find any references to help me on this.
Can you help me?
Thanks again
User | Count |
---|---|
86 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.