0

Hi have a simple link that point to a file for download:

working file link

<a href="/assets/test/myFile.pdf" download>This Works</a>

The link works but if I try to implement a download link to a file with name that contains spaces, I get a corrupted file:

not working file link

<a href="/assets/test/my File not work.pdf" download>click here to download</a>

If I check the content of the corrupted file, I can find the html content of the homepage...

How can I manage the link to download for files that contains spaces?

Thanks

Community
  • 1
  • 1
DarioN1
  • 2,460
  • 7
  • 32
  • 67
  • Possible duplicate of [How to generate url encoded anchor links with AngularJS?](https://stackoverflow.com/questions/14512583/how-to-generate-url-encoded-anchor-links-with-angularjs) – Bor Laze May 29 '17 at 12:57
  • Actually no, I have already urlencoded the link and even with the %20 is now working – DarioN1 May 29 '17 at 13:21

1 Answers1

1

Space characters aren't allowed in URL's, so you have to encode them. Have you tried to change the name of the underlying file and referencing that?

Vinorth
  • 968
  • 8
  • 13
  • I have encoded them by creating a custom pipe, the result in the page is like this: test The file in the folder is named "test senza sconto.xlsx", if I click on the link I get a file with the not rendered homepage html – DarioN1 May 29 '17 at 19:15
  • 1
    Can you rename "test senza sconto.xlsx" to "test_senza_sconto.xlsx"? This may be the easiest solution unless there is a naming convention in place and other files are dependent on it. – Vinorth May 29 '17 at 20:13
  • Yes, using the underscore it works but the customer want to use the spaces... is it possible ? – DarioN1 May 30 '17 at 05:57
  • Not that I know of. Hope you are able to find a solution. – Vinorth May 30 '17 at 13:47