Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

File Upload Service #1940


User avatar
0
avanekar02 created

Hello

Is there a built in function to do file upload , i need 2 things 1 is to store the file name and location in the database and 2nd upload that file to a location on a different server.

if so please point me to a sample.

Regards Anwar :D


7 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    The only file upload sample is in the ProfileController.ChangeProfilePicture method. It is used to upload profile picture of a user. You can also see it's client side code to understand how it works. Here, we used AJAX file uploading.

  • User Avatar
    0
    joshyates created

    I'm currently implementing Blueimp file upload into my aspnetzero example solution.

    Once completed, I'll fork.

    This is MVC5, but works very nice for multiple upload and gallery:

    <a class="postlink" href="https://github.com/CodeHeight/jQuery-File-Upload.MVC5">https://github.com/CodeHeight/jQuery-File-Upload.MVC5</a>

  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks @JoshYates, we appreciate it :)

  • User Avatar
    0
    joshyates created

    I'm taking small steps with my file upload functionality in my aspnetzero project and would like your opinion/advice.

    My current functionality: User can upload multiple files.

    Currently developing: create guid for each file uploaded. save image attributes to database. create image grouping for gallery.

    Future development: save images in Azure storage

    Where do you recommend I save uploaded images within the folder structure? I want to use the private method already created:

    private void SetAppFolders()
            {
                var appFolders = IocManager.Resolve<AppFolders>();
    

    Should I save the images in:

    Web.Mvc project contains the presentation/API layer (Controllers, Views, javascripts, styles, images and so on) for backend and frontend applications.

    or

    Web.Host project does not contain any view/css/js files. Instead, it just serves the application as remote API. So, any device can consume your application as API.

    Thank you.

    • Josh
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Did you considered storing them in database ? As you know, we already have an implementation for that.

    See, <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero/tree/5fef9a8e7b894fd9586eba9f8dc50bbd3e629b2f/src/MyCompanyName.AbpZeroTemplate.Core/Storage">https://github.com/aspnetzero/aspnet-ze ... re/Storage</a>.

    If you want to store in file system, you can create a similar class to <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero/blob/5fef9a8e7b894fd9586eba9f8dc50bbd3e629b2f/src/MyCompanyName.AbpZeroTemplate.Core/Storage/DbBinaryObjectManager.cs">https://github.com/aspnetzero/aspnet-ze ... Manager.cs</a>, in the future you can replace it with your azure blob storage implementation easily.

  • User Avatar
    0
    joshyates created

    Yes, I looked at the code for saving images in the database, but I was going to go with a file system for now. I want my client to be able to upload multiple files at once and use blueimp jquery upload. I'll save the files here:

    private void SetAppFolders()
    {
          var appFolders = IocManager.Resolve<AppFolders>();
    
          appFolders.SampleProfileImagesFolder = Path.Combine(_env.WebRootPath, @"Common\Images\SampleProfilePics");
          appFolders.TempPath = Path.Combine(_env.WebRootPath, @"Temp");
          appFolders.TempFileDownloadFolder = Path.Combine(_env.WebRootPath, @"Temp\Downloads");
          appFolders.WebLogsFolder = Path.Combine(_env.ContentRootPath, @"App_Data\Logs");
          appFolders.UploadImages = Path.Combine(_env.WebRootPath, @"Common\Upload");
          appFolders.Thumbs = Path.Combine(_env.WebRootPath, @"Common\Upload\Thumbs");
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    It is ok then.

    I suggest you to create a folder for each tenant like "Common\Uploads\1\Thumbs" or "Common\Uploads\2\Thumbs". In this way you can easily move all uploads of a single tenant easily.

    But it is up to you :)