PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 31, 2022

[FIXED] how to upload Image in Blazor server app and save the image in the folder (& in the server) save that url to the db

 July 31, 2022     blazor, blazor-server-side, file-upload, sql-server     No comments   

Issue

Ive to upload image along with the item and save this images in the local folder and the server image repository and the image url should be passed to db. (Have to combine the filepath and the physicalpath ) The code below is not working.

   @code{
         .
    .
    .
    .
    
                        foreach (var file in args.Files)
                        {
            
                            var size = file.FileInfo.Size;
                            path = "wwwroot\images\" + file.FileInfo.Name;
                            FileStream filestream = new FileStream(path, FileMode.Create, FileAccess.Write);
                            file.Stream.WriteTo(filestream);
                            filestream.Close();
                            file.Stream.Close();
                            var pathUrl = path;
             
                        }.
.
.
.

        arg.Data.ItemImage = path;
    
    }

Solution

Hy, I used this dev express control for achieving this :

https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxUpload

It needs some tuning butt in case you follow the examples it works great. Also make sure you have write premission in the folder your willing to save the files.

Give it a try, and let me know in case you got stuck.

Best regards,

Mathias



Answered By - Mathias Z
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing