1

In my SAP UI5 app, there are different types of files(pdf/doc/image) in table rows as links. links When I click on link, get_stream is called through odata service and file is downloaded. This functionality is working fine.

However I do not want to download and THEN view it. How to view the file when link is clicked. File can be image/pdf/doc/excel etc. Thanks,

  • Most of those things are driven by user settings (browser and OS), I don't think you can enforce that. – Jorg Jan 09 '20 at 00:43
  • Check what the Response Header's Content-Type and Content-Disposition are set as. The mime types need to be set correctly and Content-Disposition may have to be set to inline. – Bernard Jan 09 '20 at 12:20
  • @Bernard yes Inline opens the file in browser. However files like doc and xlsx gets downloaded because browser does not open them. – Shailendra Baranwal Jan 10 '20 at 01:55
  • @jorg you could be right. Or may be there is any header parameter that I can pass which open files in their default app. Image in photo viewer and pdf in acrobat and so on without downloading in download folder. – Shailendra Baranwal Jan 10 '20 at 01:57
  • @ShailendraBaranwal no you can’t. Browsers do not allow this. You could enforce the presence of certain apps through company policy but you have to see this in the grand scheme of things. Someone might not have adobe. Mac or Linux has different default apps etc – Jorg Jan 10 '20 at 02:22

2 Answers2

1

Its already answered in the discussion: - the very nature of a browser is to download the file if its a LINK and the operating system will take care opening the file, sometimes even in the browser (jpg, pdf files etc) - you must provide the correct http headers to make this work, see this answer: How do I force files to open in the browser instead of downloading (PDF)?

if you want to open the content stream without downloading, you must handle it within your web application - thus interpreting the stream or by using plugins, such as https://openui5.hana.ondemand.com/api/sap.m.PDFViewer or third party plugins. In this case the LINK will likely start the plugin or a page containing the plugin and use a kind of databinding.

Oliver P.
  • 46
  • 4
1

Set the Content-Disposition HTTP header on the OData service. You can do so using the /IWBEP/IF_MGW_CONV_SRV_RUNTIME~SET_HEADER of your data provider class when using SAP Gateway Foundation. Note that the browsers are not obligued to obey the Content-Disposition HTTP header, although they often do, if they can.

See more information about the Content-Disposition HTTP header and the SAP Gateway Foundation Runtime.

aboger
  • 2,214
  • 6
  • 33
  • 47