Click here to Skip to main content
       

.NET Framework

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionAdding a flash webcam photo capturememberlhsunshine16 Dec '12 - 19:33 
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
 
THIS IS MY REFERENCE LINK...
http://www.dotnetspider.com/resources/38150-Capture-save-images-from-Web-camera.aspx[^]
AnswerRe: Adding a flash webcam photo capture PinmemberEddy Vluggen17 Dec '12 - 0:42 
Does your database allow remote connections? Most hosted solutions have a firewall, preventing it.
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]
They hate us for our freedom![^]

GeneralRe: Adding a flash webcam photo capture Pinmemberlhsunshine17 Dec '12 - 1:55 
Yes, i have opened all the access... Any other idea? TQ
AnswerRe: Adding a flash webcam photo capture PinmemberEddy Vluggen17 Dec '12 - 2:01 
lhsunshine wrote:
Yes, i have opened all the access...

I'd doubt that. Create a small test-page from where you open a connection to the database, and try with that.
 
Are you using a hosted solution, or is this your "own" server?
 
What does the page do? Does it show at all? Does it show an error? What error?
 
As a side-remark; Every members' question is equally urgent.
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]
They hate us for our freedom![^]

GeneralRe: Adding a flash webcam photo capture Pinmemberlhsunshine17 Dec '12 - 2:07 
It does not show any error. When i click the "capture" button photo, the photo is captured. But does not save into the database...
QuestionRe: Adding a flash webcam photo capture PinmemberEddy Vluggen17 Dec '12 - 2:09 
Paste your database-save-code here, and we'll have a look. I assume you added an exception-handler to the example from the tutorial?
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]
They hate us for our freedom![^]

AnswerRe: Adding a flash webcam photo capture Pinmemberlhsunshine17 Dec '12 - 13:49 
Sorry for late reply. This is my code. TQ
 

Sorry for late reply. This is my code. 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;
}
}
AnswerRe: Adding a flash webcam photo capture PinmemberEddy Vluggen18 Dec '12 - 2:01 
You'll have to debug the CreatePhoto method, and verify the contents of the variables. Also verify that the user has the correct access-rights to that folder.
 
A few remarks on the code;
  • It'd be advisable to dispose objects that support it. Ideally, you'd wrap it with a using-argument, so that it gets disposed as soon as we're out of scope. E.g.;
    using (var fs = new FileStream(args here))
    {
      //place where you can access the stream
    }
  • Catching an exception just to rethrow it, is technically the same as not catching the exception in the first place. If there's an exception, write it to the screen, a logfile, anything.
  • Concatenating paths would best be done using Path.Combine.
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]
They hate us for our freedom![^]

GeneralRe: Adding a flash webcam photo capture Pinmemberlhsunshine18 Dec '12 - 18:03 
//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();
}
}
}
}
GeneralRe: Adding a flash webcam photo capture Pinmemberlhsunshine18 Dec '12 - 19:18 
I used firebug. It shows "500 Internal Server Error".
GeneralRe: Adding a flash webcam photo capture PinmemberEddy Vluggen18 Dec '12 - 20:40 
Good morning Smile | :)
 
lhsunshine wrote:
500 Internal Server Error

That's a generic message, saying something went wrong during execution of the code on the server. There'll be an exception probably, but that should have shown in your text-file now. Unless, the user isn't allowed to write there. Perhaps it's easier to display the message using Response.Write. I'm not an ASP-programmer, but the code "looks" like it should run.
 
I'm guessing that something goes wrong either by decoding the picture from Base64 (try and save the raw data, might be a nice clue for debugging) or the users' rights. Easy way to check the latter is by creating a small test-page that writes a line of text to that location.
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]
They hate us for our freedom![^]

GeneralRe: Adding a flash webcam photo capture Pinmemberlhsunshine19 Dec '12 - 2:28 
HAHA... Overhere now is night time... Smile | :)
 
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.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 25 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid