Search code examples
file-uploadasp.net-corestatic-files

how to store uploaded files in secure folder and it can be accessed securely in asp.net core?


how to store uploaded files in secure folder and it can be accessed securely in asp.net core? I knew the folder must be outside for www root folder. However, I did some google search still cannot find an example. Can someone please help me give an example or give me instructions how to setup? Thanks.

I refer to the instructions from (Serving Static Files Outside of wwwroot in Asp.NET Core 1.0) to setup. But it's still available for public access. I would like to only authorized user can access the uploaded files. how to do that? Thanks.


Solution

  • (1) The simplest solution which may depend on your server OS and access level, to adjust folder access permissions. To advise on this I would need more details from you.

    (2) A better approach I think would be to implement a handler/service that would handle public requests, and if user if authorized then stream the file's content back to the user. Yet again, depending on your server/configuration, might need to refer to (1) also.

    (3) Another option is to use a cloud blob storage, where you could set storage to be private and use their API, and issue access tokens for users to access a specific file. Tokens may be set to expire after some time as well.