简体   繁体   中英

Upload File from local computer to server c#

Is there any way to upload a PDF file that is on my local computer in a way where anyone can retrieve the PDF?

If I do something like

var filename = @"c:\test.pdf";
m.Attachments.Add(new Attachment(filename));

Anyone who goes onto the website has to have the same local path and same test.pdf file in the correct place (which would be impossible). So is there a way I can go about having to upload the pdf so it's not hard coded with a local path?

There are many ways to upload a file eg using an HTTP request and then download a file again using another HTTP request. If you just need to download files (no other API endpoints), consider using blob storage like AWS S3 bucket, Azure Blob Store or equivalents of other providers directly and configure the access rules in such a way that public read access is possible. To download the file in your program you then just need an instance of HttpClient and make a request to your blob store.

If you want to upload files through ASP.NET have a look at the Microsoft docs which describe all things to be considered in detail. You will still need to store the file somewhere when using this approach. Either on disk of the server you run the application on or again a blob store (and there are of course other possibilites).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM