102
Views
4
Comments
Solved
Expose REST that returns a file (Blob) - rename file
Question

I created a REST API that I expose to the consumer. It returns a BLOB (PowerPoint file) and works. BUT the name of the file is simply the method name "GetPowerPoint". I want it to return a custom name like "Exec Summary.pptx".

SEE THE OML attached and skip to the REMINDER note to see what I mean.

Thanks!

PowerPoint Service.oml
2021-10-09 07-57-44
Stefan Weber
 
MVP
Solution

Hi Bruce,

if you are accessing the REST endpoint directly you can also add an additional content-disposition header to your response using the AddHeader server action from the HttpRequestHandler module.

Name: content-disposition

Value: attachment; filename=\"mypowerpoint.pptx\"

This tells the browser to download the file using the provided filename. As said. This approach is only applicable when directly access the endpoint url (using the browser).

Additional information for the content-disposition header can be found here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition

Best

Stefan


2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Hi Bruce,

I think you have the wrong idea about how this all works. What you're returning from the REST service is just a stream of binary data. It's not semantically a file, even though it contains a file. So what you should do is, instead of returning the binary data in the body, create a structure that contains both the file body and the file name as attributes, and return that.

2021-10-09 07-57-44
Stefan Weber
 
MVP
Solution

Hi Bruce,

if you are accessing the REST endpoint directly you can also add an additional content-disposition header to your response using the AddHeader server action from the HttpRequestHandler module.

Name: content-disposition

Value: attachment; filename=\"mypowerpoint.pptx\"

This tells the browser to download the file using the provided filename. As said. This approach is only applicable when directly access the endpoint url (using the browser).

Additional information for the content-disposition header can be found here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition

Best

Stefan


2018-06-24 00-44-25
Bruce Buttles

Thank you @Kilian Hekhuis and @Stefan Weber! I combined both of your ideas and it is working!
Kilian, I actually used the RequestFile structure from the HTTPRequestHandler extension.

Stefan, I then used the AddHeader from the HTTPRequestHandler extension.


Now it works as I had hoped .. a simple REST call returns a well-formed file that is a PowerPoint ready to be consumed.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Glad we could help :)

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.