Coder Social home page Coder Social logo

not working about fiver.mvc.fileupload HOT 4 OPEN

tahirnaushad avatar tahirnaushad commented on August 21, 2024
not working

from fiver.mvc.fileupload.

Comments (4)

MVCLee avatar MVCLee commented on August 21, 2024 2

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.

kenneth-f-nielsen avatar kenneth-f-nielsen commented on August 21, 2024

you need to add the "wwwroot" sub folder to the projects folder.

from fiver.mvc.fileupload.

HansHammel avatar HansHammel commented on August 21, 2024

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.

sonphnt avatar sonphnt commented on August 21, 2024

Do you know why ZIP file get corrupted after downloading successfully? Thanks

from fiver.mvc.fileupload.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.