Base solution for your next web application
Open Closed

Post images to server #229


User avatar
0
stevenmunoz created

Hi !

Please some help, how can I send images from my front to the server using boilerplate ? I would really appreciate some details.

Thanks a lot


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

    Hi,

    I use angular file upload module (<a class="postlink" href="https://github.com/nervgh/angular-file-upload">https://github.com/nervgh/angular-file-upload</a>) for client side. On the server, I created an MVC controller. For excample, I use such a code to upload/change profile picture of user:

    public async virtual Task ChangeProfilePicture()
    {
        if (Request.Files.Count <= 0 || Request.Files[0] == null)
        {
            throw new UserFriendlyException(L("ProfilePicture_Change_Error"));
        }
        
        var file = Request.Files[0];
    
        if (file.ContentLength > 30720) //30KB.
        {
            throw new UserFriendlyException(L("ProfilePicture_Warn_SizeLimit"));
        }
        
        var bytes = file.InputStream.GetAllBytes();
        
        //...
    }