How to set download file name dynamically?

What is the name of the domain?

example.com

What is the issue you’re encountering

http://example.com/video.mp4?filename=abc.mp4, how to make this happen?

Screenshot of the error

sorry about the link. I just want to make an example, like


> http://somedomain.com/video.mp4?filename=abc.mp4

when users download, the filename should be abc.mp4.

Hello !

sorry about the link. I just want to make an example, like
when users download, the filename should be abc.mp4.

To further investigate, could you kindly explain regarding your expectation ?

Are you trying to modify the response header ? If yes, kindly review this document that might be related :

Thank you !

So you want to capture value from filename query string (i.e. abc.mp4 from http://somedomain.com/video.mp4?filename=abc.mp4) and add it to Content-Disposition response header, correct?

If you wanted to do this with Transform Rules, you would need to parse http.request.uri.query field and extract the filename using functions:

  • Filter: (http.request.full_uri wildcard "http://somedomain.com/*?filename=*")
  • Action: Set dynamic
  • Header name: Content-Disposition
  • Header value: concat("attachment;filename=", substring(http.request.uri.query, 9))

In this example 9 is the number of characters between the beginning of query string and the filename itself, i.e. filename= is 9 characters. This will work if your query string structure is permanently consistent, i.e. you expect clients to always request filename= and never something_else_first=123&filename=.

If you need to parse query string parts and dynamically fill the header to account for various different ways users might send query strings, I’d suggest to define such rule via JavaScript using Snippets instead. Here is an example to get you started.

1 Like