0

My website is using asp.net with c#. Recently i am adding a new function by adding a flash webcam photo capture. In local it can function well, it can capture photo, save into database, and display the photo. However, after deploy it cannot funtion well on my server. The webcam still can function. But it cannot convert and save that photo into database. I suspect the actionscript cannot fire... Do i need to install any flash player into my server? Anybody can help me? Pls help... Urgent. TQ

3
Contributors
13
Replies
15
Views
4 Years
Discussion Span
Last Post by AleMonteiro
0
//This is my code.... Pls help... TQ

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Data.SqlClient;
using Pic.User;
using Pic.Action;
using Pic.Common;

namespace Pic
{
public partial class ImageConversions : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
clsAction action = new clsAction();

DateTime thisDay = DateTime.Now;
string time = thisDay.ToString("yyyyMMMd HHmmss");
string imgMember = time + ".jpg";
string imgPath = "MemberPicture/" + imgMember;


txtAcc.Text = Session["Cust"].ToString();
lblGeoID.Text = Session["geoID"].ToString();
//lblMNo.Text = Session["memberNo"].ToString();
//lblMName.Text = Session["memberName"].ToString();
lblMember.Text = Session["Member"].ToString();
//string memberID = Convert.ToInt32(txtAcc.Text);
int memberGeoID = Convert.ToInt32(lblGeoID.Text);

CreatePhoto();

action.ExecuteInsert(imgMember, imgPath, txtAcc.Text, memberGeoID,lblMember.Text);


}

void CreatePhoto()
{
try
{
string strPhoto = Request.Form["imageData"]; //Get the image from flash file
byte[] photo = Convert.FromBase64String(strPhoto);

DateTime thisDay = DateTime.Now;
string time = thisDay.ToString("yyyyMMMd HHmmss");

//get the file name of the posted image
string imgMember = time + ".jpg";

//sets the image path
string imgPath = "MemberPicture/" + imgMember;

//then save it to the Folder
FileStream fs = new FileStream(imgPath, FileMode.OpenOrCreate, FileAccess.Write);

BinaryWriter br = new BinaryWriter(fs);
br.Write(photo);
br.Flush();
br.Close();
fs.Close();

}
catch (Exception Ex)
{
throw;
}
}
}
}
//=======================================================================================================
public void ExecuteInsert(string member, string path, string acNo, int memberGeoID, string memberNo)
{
try
{
clsDB db = new clsDB();

clsUser user = new clsUser();


SqlParameter[] sqlParams = {
new SqlParameter("@ImageMember", member),
new SqlParameter("@ImgPath", path),
new SqlParameter("@MID", acNo),
new SqlParameter("@M_GeoID", memberGeoID),
//new SqlParameter("@MNo", MNo),
//new SqlParameter("@MName", MName),
new SqlParameter("@memberNo", memberNo)
};

db.ExecuteStoredProcedure("spAddMemberPic", sqlParams);

}
catch (Exception)
{
throw;
}
}
0

You shouldn't declare the imgMember and imgPath twice(once in each function) this can lead to the image being saved with one name to the disk and in the DB with another.
Create the name only in the page load and pass it as a paramater to the CreatePhoto method.

Did you check if the image is being saved to disk but not on the DB or the vice-versa?

Another thing, you're not handling any exceptions. I'd suggest you log them to a .txt file so you can verify exatcly what's going on.

You could also use a network watcher, like FireBug or Developer's Tools to verify if the imageData parameter is being sent or not.

Another thing that may be the problem is the size of the image. Verify the request limit and request timeout on your webconfig.

Edited by AleMonteiro

0

I have added a Log.txt file. My Log.txt file is worked. I have try to input other error. Log.txt has an error message. But now is no error shown. I think it never go to this page. This page is fire from the button "Capture" in flash. I suspect the action script in flash do not fire.

0

This page that i haved pasted above. ImageConversions.aspx

Edited by lhsunshine

0

Were you able to log the exceptions?

A question, the user running the application on the server has permission to write files to the disk? If it doesn't, it would cause the error.

0

**Were you able to log the exceptions? **
When the catch() occurs save the message details into a txt file and post it back here.

0
//I have modified my code to become like this. 
//Logfile does not show any error message.
//Still cannot function well in server but can function well in local only.

namespace Pic
{
public partial class ImageConversions : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
clsAction action = new clsAction();

DateTime thisDay = DateTime.Now;
string time = thisDay.ToString("yyyyMMMd HHmmss");
string imgMember = time + ".jpg";
string fName="MemberPicture/";
string imgPath = Path.Combine(fName,imgMember);

try
{
txtAcc.Text = Session["Cust"].ToString();
lblGeoID.Text = Session["geoID"].ToString();
lblMember.Text = Session["Member"].ToString();
int memberGeoID = Convert.ToInt32(lblGeoID.Text);

CreatePhoto();

action.ExecuteInsert(imgMember, imgPath, txtAcc.Text, memberGeoID, lblMember.Text);
lblMsg.Text = "Success";
}
catch (Exception ex)
{
FileInfo txt = new FileInfo("Log.txt");
StreamWriter sw = txt.AppendText();
sw.WriteLine(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss tt") + " " + "Line No:" + ex.Source + " Message " + ex.Message);
sw.WriteLine(" ");
sw.WriteLine(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss tt") + " " + ex.StackTrace);
sw.WriteLine(" ");
sw.WriteLine(" ");
sw.Close();
}


}

void CreatePhoto()
{
try
{
string strPhoto = Request.Form["imageData"]; //Get the image from flash file
byte[] photo = Convert.FromBase64String(strPhoto);

DateTime thisDay = DateTime.Now;
string time = thisDay.ToString("yyyyMMMd HHmmss");

//get the file name of the posted image
string imgMember = time + ".jpg";
string fName = "MemberPicture/";
string imgPath = Path.Combine(fName, imgMember);

string fileName = Path.Combine(fName,imgPath);
using (var fs = new FileStream(imgPath, FileMode.OpenOrCreate, FileAccess.Write))
{
// read the file
BinaryWriter br = new BinaryWriter(fs);
br.Write(photo);
br.Flush();
br.Close();
fs.Close();
}
}
catch (Exception ex)
{
FileInfo txt = new FileInfo("Log.txt");
StreamWriter sw = txt.AppendText();
sw.WriteLine(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss tt") + " " + "Line No:" + ex.Source + " Message " + ex.Message);
sw.WriteLine(" ");
sw.WriteLine(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss tt") + " " + ex.StackTrace);
sw.WriteLine(" ");
sw.WriteLine(" ");
sw.Close();
}
}
}
}
0

Try like this and see if it works or if it writes the exception on Log.txt.
Also, make sure that the folder MemberPicture exists on the server.

namespace Pic
{

    public partial class ImageConversions : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            clsAction action = new clsAction();

            DateTime thisDay = DateTime.Now;
            string time = thisDay.ToString("yyyyMMMd HHmmss");
            string imgMember = time + ".jpg";
            string fName="MemberPicture/";
            string imgPath = Path.Combine(fName,imgMember);

            try
            {
                txtAcc.Text = Session["Cust"].ToString();
                lblGeoID.Text = Session["geoID"].ToString();
                lblMember.Text = Session["Member"].ToString();
                int memberGeoID = Convert.ToInt32(lblGeoID.Text);

                CreatePhoto(imgPath);

                action.ExecuteInsert(imgMember, imgPath, txtAcc.Text, memberGeoID, lblMember.Text);
                lblMsg.Text = "Success";
            }
            catch (Exception ex)
            {
                LogException(ex);
            }


        }

        protected void CreatePhoto(string imgPath)
        {
            try
            {
                string strPhoto = Request.Form["imageData"]; //Get the image from flash file
                byte[] photo = Convert.FromBase64String(strPhoto);

                string fileName = Path.Combine(fName,imgPath);
                using (var fs = new FileStream(imgPath, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    // read the file
                    BinaryWriter br = new BinaryWriter(fs);
                    br.Write(photo);
                    br.Flush();
                    br.Close();
                    fs.Close();
                }
            }
            catch (Exception ex)
            {
                LogException(ex);
            }
        }

        protected void LogException(Exception ex)
        {
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(Server.MapPath("~/Log.txt"), true))
            {
                file.WriteLine(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss tt") + " " + "Line No:" + ex.Source + " Message " + ex.Message);
                file.WriteLine(" ");
                file.WriteLine(DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss tt") + " " + ex.StackTrace);
                file.WriteLine(" ");
                file.WriteLine(" ");
            }
        }
    }

}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.