Skip to Content
0
Jun 03, 2020 at 11:47 AM

XS File API PUT not working from XSJS code

240 Views

Hi Experts,

I am trying to change a file in HANA Cloud DB (Neo - XSC).

When I used GET method to fetch the data from the file, it was working - but when I am using PUT method its returning as "403 Forbidden".

Where I am doing wrong, not getting at all.

XSHTTPDEST File ->

host = "XXXXXXXXtrial.hanatrial.ondemand.com";
port = 443;
pathPrefix = "/sap/hana/xs/dt/base/file";
proxyType = http;
proxyHost = "proxy";
proxyPort = 8080;
authType = basic;
useSSL = true;
timeout = 0;
sslAuth = anonymous;

Please find the code snippet below ->

// PUT Method for XS File API
function setDict(xcsrfToken, dictBody) {
	var dest = $.net.http.readDestination("{{dest_path}}", "{{dest_filename}}");
	var client = new $.net.http.Client();
	var req = new $.net.http.Request($.net.http.PUT, "/{{file_path}}/{{file_name}}");
	req.headers.set("x-csrf-token", xcsrfToken);
	req.headers.set("Content-Type", 'text/plain');
	req.setBody(dictBody);
	client.request(req, dest);
	var response = client.getResponse();
	return response;
}

// API Logic
var xcsrfToken = $.session.getSecurityToken();
var dictBody = $.request.body.asString();
var response = fLib.setDict(xcsrfToken,dictBody);
$.response.contentType = "text/plain";
$.response.setBody(xcsrfToken);
$.response.setBody(JSON.stringify(response.headers));

But the response I am getting is forbidden:

{
    "0": {
        "name": "~response_line",
        "value": "HTTP/1.1 403 Forbidden"
    },
    "1": {
        "name": "~server_protocol",
        "value": "HTTP/1.1"
    },
    "2": {
        "name": "~status_code",
        "value": "403"
    },
    "3": {
        "name": "~status_reason",
        "value": "Forbidden"
.................................

}