aspnet / StaticFiles

[Archived] Middleware for handling requests for file system resources including files and directories. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
114 stars 72 forks source link

File names with %20 doesn't get served #179

Closed dhanilan closed 7 years ago

dhanilan commented 7 years ago

Steps to Reproduce :

  1. Create an Empty dotnet core Wep API project from Visual studio.
  2. Add StaticFiles package to the project.
  3. Add the following code to the startup.cs Configure Method
    app.UseFileServer(new FileServerOptions()
    {    
        FileProvider = new PhysicalFileProvider(
    Path.Combine(Directory.GetCurrentDirectory(), @"StaticFiles")),
        RequestPath = new PathString("/StaticFiles"),
        EnableDirectoryBrowsing = true
    });
  4. Add the folder in the Directory "StaticFiles".
  5. Add any file with '%20' in filename . Ex:- 'FileName%20WithPercentEncodedSpace.pdf'
  6. Run the application. And browser for the directory http://localhost:19390/StaticFiles.
  7. File list will contain FileName%20WithPercentEncodedSpace.pdf . but will not open when clicked.
dhanilan commented 7 years ago

Also tried http://localhost:19390/StaticFiles/FileName%2520WithPercentEncodedSpace.pdf . Doesn't work!

Tratcher commented 7 years ago

This isn't unique to %20, you'll have this problem with most escape sequences. When your file names start conflicting with URI syntax there are limits to what will be addressable. Decode the space and it will work fine.

dhanilan commented 7 years ago

@Tratcher I tried decoding the URI . In this case decodeURI('FileName%20WithPercentEncodedSpace.pdf') results in "FileName WithPercentEncodedSpace.pdf". but get of http://localhost:19390/StaticFiles/FileName WithPercentEncodedSpace.pdf doesn't work!!!! since the file is stored as FileName%20WithPercentEncodedSpace.pdf . I cannot change the filename because it comes from an external system.