Home > Mobile >  How to get the URL of a file uploaded on a server in C#.net web application?
How to get the URL of a file uploaded on a server in C#.net web application?

Time:05-21

I am presently working on a C#.net Web Application which supports file uploads to the server by users. I am using an external WhatsApp API which needs to access these files using a URL. So, I am wondering as to what URL should I pass to the API so that it can access files on the server.

Will the URL be something like: base_url/file_path/file_name?

Also, what changes will I have to make in the route configuration file for the same (because, presently the default url pattern is base_url/controller/action)

CodePudding user response:

Based on the above discussion, i can see 'DocumentMessage' is the model where its asking. I have 2 ways to handle. you can pick any based on your system design.

  1. This is the approach where your app don't need any Cloud involvement. Irrespective of Hosting in IIS(on premise) or any Any Cloud service app, it will work. But only requirement is File need to be there in the Project folder structure.

Solution:- Create a Virtual path under your root directory. So your api/ website will be hosted under some domain(https://example.com) . So your Virtual directory path will be something like (https://example.com/fileLocation). So your entire file path will be published under this link. so for your File the path will be https://abc.or/fileLocation/file_Data

Note:- Disable the Directory access for your security purpose. Without fail

Reference:- For IIS Virtual Path For Azure App service

  1. If possible put your file in some Cloud storage(e.g. Blob storage container) & fetch the blob Url. you need to store the URL in the Database(for reusing it or storing instead of calling multiple time to Cloud to get the path).
  • Related