1

I have a url that returns a file, but the problem is that in the Firefox browser, the file is displayed correctly, but in the Chrome and Edge browsers, it downloads instead of displaying. None of the solutions I searched for solve this problem correctly, please. guide me

<iframe 
  style={style} width="100%" height="100%"
  src={`/test?letterReference=${this.props.letterReference}&fileReference=${this.props.fileReference}#toolbar=0&navbar=0`}>
</iframe>
goodboy
  • 31
  • 4

1 Answers1

1

To display a file you could also use an <object>:

<object data="{`/test?letterReference=${this.props.letterReference}&fileReference=${this.props.fileReference}#toolbar=0&navbar=0`}" width="100%" height="100%"></object>
Mikelo
  • 271
  • 2
  • 16
  • This solution does not work because Chrome sometimes calls the address twice and causes it to be blocked @Mikelo – goodboy Jul 10 '23 at 11:05
  • Does your url refers to an exact file location or to a handler which provides the file? – Mikelo Jul 10 '23 at 11:08
  • No, there is a controller that extracts the necessary data from the url I send and returns it @Mikelo – goodboy Jul 10 '23 at 11:11
  • Ok. Could you share the header response of the url you try to display? Check if Content-Disposition is set correctly so the browser knows it has to view the file instead of download it – Mikelo Jul 10 '23 at 11:17
  • What should be set inside the header for Content-Disposition? @Mikelo – goodboy Jul 10 '23 at 11:30
  • It should set to 'inline' to view a file, whereas 'attachment' would force download – Mikelo Jul 10 '23 at 12:43