Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9228697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:23:19+00:00 2026-06-18T05:23:19+00:00

What is the Best way to store an image uploaded by the user and

  • 0

What is the Best way to store an image uploaded by the user and then show it in my website?

  1. Store it as binary in DB. then how should I show it with `img`?
    I think I should write it to a directory somehow then pass it’s address as `src` attribute of `img`.

  2. I can store it somewhere in web server, store the address of image in database. then I should simply specify the address in database in `src` attribute.
  3. Other ways?!

in my opinion the second way is more convenient.
and another question!
In both case How Can I upload this images in html form? the @Html doesent hav anything like @Html.FileFor(...) and how can I get data of <input type='file'/> in my Action?
I appreciate any suggestion.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:23:20+00:00Added an answer on June 18, 2026 at 5:23 am

    in my opinion the second way is more convenient.

    Yeah in my opinion as well.

    In both case How Can I upload this images in html form?

    Pretty easy. As always in an ASP.NET MVC application you start by designing a view model:

    public class MyViewModel
    {
        [Required]
        public HttpPostedFileBase File { get; set; }
    }
    

    then you could have a controller with 2 actions (one rendering the view and another handling the file upload):

    public class HomeController: Controller
    {
        public ActionResult Index()
        {
            return View(new MyViewModel());
        }
    
        [HttpPost]
        public ActionResult Index(MyViewModel model)
        {
            if (!ModelState.IsValid)
            {
                // the user didn't upload any file =>
                // render the same view again in order to display the error message
                return View(model);
            }
    
            // at this stage the model is valid => 
            // you could handle the file upload here
    
            // let's generate a filename to store the file on the server
            var fileName = Guid.NewGuid().ToString() + Path.GetFileName(file.FileName);
            var path = Path.Combine(Server.MapPath("~/App_Data"), fileName);
            // store the uploaded file on the file system
            file.SaveAs(path);
    
            // TODO: now you could store the path in your database
    
            // and finally return some ActionResult
            // to inform the user that the upload process was successful
            return Content("Thanks for uploading. Your file has been successfully stored on our server");
        }
    }
    

    and finally you will have a corresponding strongly typed view that will contgain the form to upload the file:

    @model MyViewModel
    @using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
        <div>
            @Html.LabelFor(x => x.File)
            @Html.TextBoxFor(x => x.File, new { type = "file" })
            @Html.ValidationMessageFor(x => x.File)
        </div>
        <button type="sybmit">Upload</button>
    }
    

    Also I would recommend you reading Phil Haack's blog post that illustrates file uploading in ASP.NET MVC works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the best way to store images? Currently when an image is uploaded
What's the best way to store an image in a database in binary format,
The best way to store images into MySQL is by storing the image location
The question is quite easy: what is the best way to store uploaded files
What's the best way to store ordered lists in a database, so that updating
What is the best way to store a 2D matrix of integers in Java?
What is the best way to store sound files (ogg) that are distributed with
What is the best way to store and handle sensitive information with puppet and
What's the best way to store connection string info? I'd rather not just store
What is the best way to store data that is dynamic in nature using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.