cancel
Showing results for 
Search instead for 
Did you mean: 

How to call a Media File(PDF) in odata service (OModel.read) form backend to frontend in sapui5

Former Member

I have been working on the SAPUI5 and I try to get a PDF File from backend when we test it in the SAP Gateway Client "EntitySet()/$value" it's working

~status_code 200

~status_reason OK

but in button press function the oModel.read code gives an error.

Cannot read property 'body' of undefined

My button code :

function() {

var value = this.getView().byId("inputValue").getValue();

var sRead = "/PrintProcessSet(Tknum='" + value + "')/$value";

var html = new sap.ui.core.HTML();

var oModel = this.getView().getModel();

oModel.read(sRead, {

success: function(oData, oResponse) {

var response = oResponse.requestUri;

html.setContent("<iframe src=" + response + " width='700' height='700'></iframe>");

var windows = window.open("", "My PDF", " width='700' height='700'");

windows.document.write(html);

windows.print();

windows.close();

},

error: function() {

alert("Read failed");

}

});

},

We get the Following error

Failed to load resource: the server responded with a status of 404 (Not Found) jquery.sap.global-dbg.js:

1022 2017-10-11 11:41:58.602000 [extended_runnable_file.html] The following problem occurred: no handler for data - O @ jquery.sap.global-dbg.js:1022 Q.fatal @ jquery.sap.global-dbg.js:1066 r._handleError @ VM63:2741 r._processError @ VM63:2734 v @ VM63:2726 w @ VM63:2726 v @ VM63:2723 (anonymous) @ VM63:2790 (anonymous) @ datajs.js:17 p9 @ datajs.js:17 datajs.js:17

Uncaught TypeError: Cannot read property 'body' of undefined

at constructor.r._createEventInfo (eval at evalModuleStr (jquery.sap.global-dbg.js:3406), <anonymous>:2683:1013)

at constructor.r._processSuccess (eval at evalModuleStr (jquery.sap.global-dbg.js:3406), <anonymous>:2733:1605)

at w (eval at evalModuleStr (jquery.sap.global-dbg.js:3406), <anonymous>:2726:831)

at v (eval at evalModuleStr (jquery.sap.global-dbg.js:3406), <anonymous>:2723:122)

at eval (eval at evalModuleStr (jquery.sap.global-dbg.js:3406), <anonymous>:2790:272)

at eval (datajs.js:17) at XMLHttpRequest.p9 (datajs.js:17)

Accepted Solutions (0)

Answers (4)

Answers (4)

jr_golive
Explorer
0 Kudos

Hello.

Did any of you guys find an answer to this issue? I'm facing it, just like you. The only difference is that I want to print it out. I want to display it first, so I can be sure I've retrieved it from the back end (which works properly when I test it in the Gateway, or a web browser by it self).

benlim
Contributor
0 Kudos

Hi,

I'm having the same issues. Does this resolved?

Regards,

Ben

venkatachala_ck
Active Participant
0 Kudos

Hello Yen Shen,

check out this link

https://sapui5.hana.ondemand.com/#/sample/sap.m.sample.PDFViewerEmbedded/preview

i think there is no need of oModel.read method for pdf viewer

just you have to set the url for iframe itself

<html:iframe id="frameId" src=""> </html:iframe>

this.getView().byId(frameId).setSrc("Place ur URI here");

Thanks

Venkat

benlim
Contributor
0 Kudos

Hi @Venkatachala C.K,

I've checked this controller. However, I need to display my pdf when using mobile device. This controller only support for desktop mode.

Thanks.

Regards,

Ben

venkatachala_ck
Active Participant
0 Kudos

In mobile it is not possible to view it seems, so better to download the file and view it.

benlim
Contributor
0 Kudos

If this case, can we conclude using mobile, we are not able to display PDF view?

venkatachala_ck
Active Participant
0 Kudos

May be Yes, because in the past even i have faced this problem and finally i told them using Mobile its not possible to view PDF until unless it is downloaded.

former_member185414
Active Contributor
0 Kudos

The behavior of media stream is controlled by the content disposition header set in the response header. You should check what value is set in the Read_Stream/Get_Stream method. To enable opening in browser tab you need to set it as inline and properly set the mime type based on file attributes.

benlim
Contributor
0 Kudos

Hi Maskara,

I've confirmed it's not about get_stream method issue. The call from odata was success from backend.

I've tried to insert a hard coded pdf url value in iframe, it's not able to load the pdf in my app in browser mode. My PDF is able to display in pdf view controller in desktop mode as suggestion by Venkatachala C.K. PDFViewer

The current issue is how am I able to display my PDF in mobile mode.

former_member185414
Active Contributor
0 Kudos

Thanks Ben, so basically you have set the correct content headers but still it's not working in mobile. Will wait for solution.

0 Kudos

are you able to solve this issue?

regards

Manik Saluja

former_member340030
Contributor
0 Kudos
Former Member
0 Kudos

Hi Viplove Khushalani,

I have checked the blog and also added my Question, I have followed the same steps but I get this issue.

Thanks for your help

Sabari .