One project is a blank website named FileUploader. This file can be easily downloaded from the Nuget Gallery or from the Angular website. Js and FileUploader. Js and add the following code. JS and define the controller in that file as in the following. Now our objective is, after selecting the file, it will automatically read the file and show the file size in the page.
For this purpose, we called the onchange event of the file upload control and written the following code. Now our next objective is to upload the file using the Web API so that this specific file can be copied and saved in a specific location.
For this, we already created a button name Upload. We need to click on this button for uploading. When we click this button, it will call an AngularJs function that internally redirects to the Web API controller to copy and save the file into a specific location.
Here I am using Temporary Internet Files folder for the location. Now write the following code first into the fileupload. And the uploadComplete function checks if the Web API returns a status code in other words success or not. Now for the Web API code. For that, we will add a controller file within the controller folder named FileUploaderController and write the following code in that file. Generic; using System. IO; using System. Linq; using System. TravisO TravisO 9, 4 4 gold badges 34 34 silver badges 44 44 bronze badges.
Please don't make up headers and send them. Could you update your answer. Be careful when using this code verbatim, though. This code is likely dangerous in another way. Could be used by an attacker to attempt to scan your internal network for exposed PDF files.
Not to mention how easy it would be to bypass any "sanity checks" you think you'll be doing to the "file" parameter. Show 8 more comments. Alex V Alex V The readfile function is indeed faster. I personally recommend using this answer instead of the accepted one — Jose Garrido. Rob W Rob W k 76 76 gold badges silver badges bronze badges. TecBrat Yes, but that was what the OP asked. TecBrat or put the. Alex W Alex W Sudden Def Sudden Def 8, 3 3 gold badges 17 17 silver badges 8 8 bronze badges.
I know I am very late to answer this but I found a hack to do this in javascript. Shivek Parmar Shivek Parmar 2, 2 2 gold badges 31 31 silver badges 42 42 bronze badges. This can be achieved using HTML. Okiemute Gold Okiemute Gold 8 8 bronze badges. Peter O. Podcast Who is building clouds for the independent developer? Featured on Meta. Now live: A fully responsive profile. Reducing the weight of our footer.
Linked 6. Related Hot Network Questions. Question feed. Stack Overflow works best with JavaScript enabled. Accept all cookies Customize settings. Examples might be simplified to improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use , cookie and privacy policy. Copyright by Refsnes Data. All Rights Reserved.
0コメント