Image upload question

  • Thread starter Thread starter Guy
  • Start date Start date
G

Guy

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?
 
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-Tutorials/Binary-Files-To-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


g> I'm trying by means of a FileUpload control and and "Apply" button,
g> brwosong
g> my local folders for a picture file loading (Apply button) and
g> displaying the
g> (local) picture (jpg, gif, ..) file. I don't want the local file to
g> be saved
g> on the server but displayed on my webform and if ok be stored in my
g> database
g> together with other related info.
g> I googled and found some example .. but not exactly what i want to
g> achieve.
g> Anyone can give me a hint where to start?
g>
 
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
 
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.PostedFile.ContentType;
if (contentType.StartsWith("image/"))
{
Session["uploadFile"] = fuTest.FileBytes;
imgPreview.Visible = true;
imgPreview.ImageUrl = "image_preview.ashx";
}
}
}

// image_preview.ashx
<%@ WebHandler Language="C#" Class="image_preview" %>

using System;
using System.Web;
using System.Web.SessionState;

public class image_preview : IHttpHandler, IRequiresSessionState {

public void ProcessRequest (HttpContext context) {
byte[] img = (byte[])context.Session["uploadFile"];
if (img != null)
{
context.Response.ContentType = "image";
context.Response.OutputStream.Write(img, 0, img.Length);
// clear session
context.Session["uploadFile"] = null;
}
}
public bool IsReusable {
get {
return false;
}
}
}
 
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


g> Thanks for the info.
g>
g> I want, before storing the picture in the db, already display the
g> image on the webform and save to the db when all other info has been
g> entered. If I'm right the example link you provided doesn't handle
g> this displaying of the image before storing to the db?!
g>
g> Regards,
g> Guy
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-Tutorials/Binary-Files-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

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