0

I have a web app running AngularJS on the frontend with a WebAPI on the backend running on IIS 8.5.

I generate links to download files from the server, encode them, and send them to a Wordpress site through a REST API. Everything works great as expected except when the generated URL contain spaces, the URL decoded on the Wordpress site convertes the %2B to + sign and I get a 404 error when trying to donwload the file. So I found this answer explaining that I need to add the allowDoubleEscaping setting, done.

Now I don't get a 404 error but the site redirects to the default page and I thinks this has something to do with the Angular router but I couldn't find anything related to it. This the an example URL: https://example.com/Content/data/hello+world.jpg-6c2b9156-079b-4632-8374-b06361ee6d1c.gcode

This are the URL Rewrite rules on the server:

<rewrite>
  <rules>
    <rule name="Root Hit Redirect" stopProcessing="true">
      <match url=".*" />
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
        <!--<add input="{REQUEST_URI}" pattern="^/(token)" negate="true" />-->
      </conditions>
      <action type="Rewrite" url="/" />
    </rule>
  </rules>
</rewrite>

And this is my router in Angular:

$locationProvider.html5Mode(true);
$routeProvider.when("/signin", {
    templateUrl: "app/views/signin.html",
});

$routeProvider.when("/home", {
    templateUrl: "app/views/home.html",
});

$routeProvider
    .when('/', { redirectTo: '/home' })
    .when('/404', { templateUrl: 'app/views/pages/404.html' })
    .otherwise({ redirectTo: '/' });

I think angular is assuming an invalid URL and is redirecting me to the default page instead of letting me download the file.

EDIT:

I don't think this is the same as in the question Angularjs simple file download. The accepted answer suggests to add a target="_self" to prevent the redirection but I can't do this because I not downloading the referenced file in the URL with an anchor tag.

I just give the URLs to the user and they copy and paste it in the URL bar of their browser to download the file and I need it to work on that way. The same applies with the answers giving a directive as a solution.

Basically the link is given to the users in the Wordpress site which is out of my control so I just need to accept URL with + instead of %2B. I hope its clearer now.

Community
  • 1
  • 1
Andres
  • 6,080
  • 13
  • 60
  • 110

0 Answers0