Comments (4)
I got this working with the following code:
public HomeController(IFileProvider fileProvider, IHostingEnvironment environment)
{
this.fileProvider = fileProvider;
this.hostingEnvironment = environment;
}
public IActionResult Index()
{
return View();
}
[HttpPost]
public async Task<IActionResult> UploadFile(IFormFile file)
{
if (file == null || file.Length == 0)
return Content("file not selected");
Guid guid = Guid.NewGuid(); // created guid
var uploadedFileName = guid + Path.GetFileName(file.FileName); // added guid to filename
var path = Path.Combine(
//Directory.GetCurrentDirectory(), "wwwroot", this line didn't work...
hostingEnvironment.WebRootPath + "\\documents\\", uploadedFileName); // works
using (var stream = new FileStream(path, FileMode.Create))
{
await file.CopyToAsync(stream);
}
return RedirectToAction("Files");
}
from fiver.mvc.fileupload.
you need to add the "wwwroot" sub folder to the projects folder.
from fiver.mvc.fileupload.
nope. done that. The part where the stream is written to disk is overwriting the local file. I think this wasn't testet or run on a local machine. The path concationation was wrong (last part is the local path that gets evaliuated first, the rest is skipped) and maybe other things were wrong or not working I dont remember... Btw. this was super fast, because we don't use any api insted the local file (as far as I remmeber the local path will be send in the Name property of the form) can be copied, if you fix the target issue mentioned above - nice approach ;-)
from fiver.mvc.fileupload.
Do you know why ZIP file get corrupted after downloading successfully? Thanks
from fiver.mvc.fileupload.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fiver.mvc.fileupload.