Image upload question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?R3V5?=

    Image upload question

    I'm trying by means of a FileUpload control and and "Apply" button, brwosong
    my local folders for a picture file loading (Apply button) and displaying the
    (local) picture (jpg, gif, ..) file. I don't want the local file to be saved
    on the server but displayed on my webform and if ok be stored in my database
    together with other related info.
    I googled and found some example .. but not exactly what i want to achieve.

    Anyone can give me a hint where to start?

  • Michael Nemtsev [MVP]

    #2
    Re: Image upload question

    Hello guy,

    What you need to do is upload in to server when you click ok. Example is
    there http://www.beansoftware.com/ASP.NET-...-Database.aspx

    So, what is the problem?!

    ---
    WBR,
    Michael Nemtsev [Microsoft MVP] :: blog: http://spaces.live.com/laflour
    :: http://twitter.com/laflour

    "The greatest danger for most of us is not that our aim is too high and we
    miss it, but that it is too low and we reach it" (c) Michelangelo


    gI'm trying by means of a FileUpload control and and "Apply" button,
    gbrwosong
    gmy local folders for a picture file loading (Apply button) and
    gdisplaying the
    g(local) picture (jpg, gif, ..) file. I don't want the local file to
    gbe saved
    gon the server but displayed on my webform and if ok be stored in my
    gdatabase
    gtogether with other related info.
    gI googled and found some example .. but not exactly what i want to
    gachieve.
    gAnyone can give me a hint where to start?
    g>


    Comment

    • =?Utf-8?B?R3V5?=

      #3
      Re: Image upload question

      Thanks for the info.

      I want, before storing the picture in the db, already display the image on
      the webform and save to the db when all other info has been entered. If I'm
      right the example link you provided doesn't handle this displaying of the
      image before storing to the db?!

      Regards,
      Guy



      "Michael Nemtsev [MVP]" wrote:
      Hello guy,
      >
      What you need to do is upload in to server when you click ok. Example is
      there http://www.beansoftware.com/ASP.NET-...-Database.aspx
      >
      So, what is the problem?!
      >
      ---
      WBR,
      Michael Nemtsev [Microsoft MVP] :: blog: http://spaces.live.com/laflour
      :: http://twitter.com/laflour
      >
      "The greatest danger for most of us is not that our aim is too high and we
      miss it, but that it is too low and we reach it" (c) Michelangelo
      >
      >
      gI'm trying by means of a FileUpload control and and "Apply" button,
      gbrwosong
      gmy local folders for a picture file loading (Apply button) and
      gdisplaying the
      g(local) picture (jpg, gif, ..) file. I don't want the local file to
      gbe saved
      gon the server but displayed on my webform and if ok be stored in my
      gdatabase
      gtogether with other related info.
      gI googled and found some example .. but not exactly what i want to
      gachieve.
      gAnyone can give me a hint where to start?
      g>
      >
      >
      >

      Comment

      • Ben Amada

        #4
        Re: Image upload question

        On Sep 24, 1:15 pm, Guy <G...@discussio ns.microsoft.co mwrote:
        I'm trying by means of a FileUpload control and and "Apply" button, brwosong
        my local folders for a picture file loading (Apply button) and displayingthe
        (local) picture (jpg, gif, ..) file. I don't want the local file to be saved
        on the server but displayed on my webform and if ok be stored in my database
        together with other related info.
        I googled and found some example .. but not exactly what i want to achieve.
        >
        Anyone can give me a hint where to start?
        An approach is when the user clicks the Submit or Preview button, the
        file gets posted to the server, you temporarily store the file in
        Session. On the same page, you have an Image control and you set its
        ImageUrl property to an ASHX handler page that will serve the image to
        the client. In the ASHX page, you get the file out of session, send
        it to the client and clear the file out of session. All this is done
        within a couple of seconds so the image doesn't stick around in
        session very long. Here's some sample code that does this:

        // ASPX page code-behind
        protected void btnSubmit_Click (object sender, EventArgs e)
        {
        if (fuTest.HasFile )
        {
        string contentType = fuTest.PostedFi le.ContentType;
        if (contentType.St artsWith("image/"))
        {
        Session["uploadFile "] = fuTest.FileByte s;
        imgPreview.Visi ble = true;
        imgPreview.Imag eUrl = "image_preview. ashx";
        }
        }
        }

        // image_preview.a shx
        <%@ WebHandler Language="C#" Class="image_pr eview" %>

        using System;
        using System.Web;
        using System.Web.Sess ionState;

        public class image_preview : IHttpHandler, IRequiresSessio nState {

        public void ProcessRequest (HttpContext context) {
        byte[] img = (byte[])context.Sessio n["uploadFile "];
        if (img != null)
        {
        context.Respons e.ContentType = "image";
        context.Respons e.OutputStream. Write(img, 0, img.Length);
        // clear session
        context.Session["uploadFile "] = null;
        }
        }
        public bool IsReusable {
        get {
        return false;
        }
        }
        }

        Comment

        • Michael Nemtsev [MVP]

          #5
          Re: Image upload question

          Hello guy,

          But how are you going to show the image if file don't exist anywhere?! It
          should be uploaded somewhere first, to temporary location I'd say and then
          you need to show it.

          You can use sessions or cache, but file must be on server to be shown

          ---
          WBR,
          Michael Nemtsev [Microsoft MVP] :: blog: http://spaces.live.com/laflour
          :: http://twitter.com/laflour

          "The greatest danger for most of us is not that our aim is too high and we
          miss it, but that it is too low and we reach it" (c) Michelangelo


          gThanks for the info.
          g>
          gI want, before storing the picture in the db, already display the
          gimage on the webform and save to the db when all other info has been
          gentered. If I'm right the example link you provided doesn't handle
          gthis displaying of the image before storing to the db?!
          g>
          gRegards,
          gGuy
          g"Michael Nemtsev [MVP]" wrote:
          g>
          >Hello guy,
          >>
          >What you need to do is upload in to server when you click ok. Example
          >is there
          >http://www.beansoftware.com/ASP.NET-...les-To-Databas
          >e.aspx
          >>
          >So, what is the problem?!
          >>
          >---
          >WBR,
          >Michael Nemtsev [Microsoft MVP] :: blog:
          >http://spaces.live.com/laflour
          >:: http://twitter.com/laflour
          >"The greatest danger for most of us is not that our aim is too high
          >and we miss it, but that it is too low and we reach it" (c)
          >Michelangelo
          >>
          >gI'm trying by means of a FileUpload control and and "Apply"
          >button,
          >gbrwosong
          >gmy local folders for a picture file loading (Apply button) and
          >gdisplaying the
          >g(local) picture (jpg, gif, ..) file. I don't want the local file
          >to
          >gbe saved
          >gon the server but displayed on my webform and if ok be stored in
          >my
          >gdatabase
          >gtogether with other related info.
          >gI googled and found some example .. but not exactly what i want to
          >gachieve.
          >gAnyone can give me a hint where to start?
          >g>

          Comment

          Working...