Hi all!
I have a blob field in my table in an Oracle database. I also have a Java rest service that returns me this field in a form of a Response, something like:
return Response.ok(stream, MediaType.APPLICATION_OCTET_STREAM).header("content-disposition", "attachment; filename = " + artefato.getTitulo()) .build();
Very well, In my Hana XS application I'm trying to download this file, calling that rest service and getting the response. I wrote a service lik this:
//**** Example for basic REQUEST RESPONSE handling
var paramName; var paramValue; var headerName; var headerValue; var contentType;
//Implementation of GET call
function handleGet() { var buffer // Call rest service if (resp.status == 200) { buffer = resp.data.asString() $.response.contentType = 'application/octet-stream' $.response.headers.set("content-disposition", resp.headers.get('content-disposition')) $.response.status = $.net.http.OK } else { $.response.contentType = 'application/json' buffer = JSON.stringify(resp) + utils.translatePath(path, params) } return buffer
}
// Request process
function processRequest(){ try { switch ( $.request.method ) { //Handle your GET calls here case $.net.http.GET: $.response.setBody(handleGet()); break; default: $.response.status = $.net.http.METHOD_NOT_ALLOWED; $.response.setBody("Wrong request method"); break; } } catch (e) { $.response.setBody("Failed to execute action: " + e.toString()); }
}
// Call request processing
processRequest();And in my controller I biult a function to handle the download:
attachmentDownload: function(oEvt) { var params = this.getParams() params.attachmentId = oEvt.getParameter("attachmentId") params.execucaoId = oEvt.getParameter("execucaoId") var url = Config.getUrlFor("mymappedurl", params) // TODO better way to download the file //window.open(url) window.location.href = url },Problem is when I try to open the file it comes corrupted, and don't open at all. This happens for zip, pdf, etc and only works with txt files. Can someone help me and show what am I doing wrong? Thanks in advance!!