将图像保存到sql server或文件夹名称中.Web应用程序中的图像

时间:2022-06-18 06:13:54

I have one save button which will save the image in the desktop from camera when button is click below is the code.....

我有一个保存按钮,当按下单击下面的代码时,会将图像从相机保存在桌面上.....

<input id="Save" style="Z-INDEX: 1; LEFT: 8px; WIDTH: 128px; TOP: 36px; HEIGHT: 24px"
                                        onclick="return save_onclick()" type="button" value="Save Image" name="save">

function save_onclick()
{
    document.AxuEyeCam.SaveImage("test.jpg");       
}

It not good to save image in one pc because the image will not be available worldwide, it will be available for only to the pc which has image.

将图像保存在一台电脑中并不好,因为图像在全球范围内不可用,只能用于有图像的电脑。

what i think is to save image in web application using mappath or store image in sql server or may be in cloud so that image will be available worldwide.

我认为在sql server中使用mappath或store image保存Web应用程序中的图像,或者可能在云端,以便图像可在全球范围内使用。

Can anybody suggest me how this is possible.

任何人都可以建议我这是如何可行的。

Thanks a lot

非常感谢

2 个解决方案

#1


1  

Here is the Steps

这是步骤

1- Create a web service and host it in a server ( the web service will contain a web method to upload your file and save it to a server)

1-创建Web服务并将其托管在服务器中(Web服务将包含用于上载文件并将其保存到服务器的Web方法)

2- Call the web service from your application ( Desktop application or web application )

2-从您的应用程序调用Web服务(桌面应用程序或Web应用程序)

Here is a Good Example for the web service and the client application

这是Web服务和客户端应用程序的一个很好的示例

http://www.c-sharpcorner.com/uploadfile/scottlysle/uploadwithcsharpws05032007121259pm/uploadwithcsharpws.aspx

http://www.c-sharpcorner.com/uploadfile/scottlysle/uploadwithcsharpws05032007121259pm/uploadwithcsharpws.aspx

I don't recommend saving the image as binary in the database because you may find it harder to retrieve and display

我不建议将图像保存为数据库中的二进制文件,因为您可能会发现它更难以检索和显示

I do recommend saving the file name in the sql server table and save the image itself to a separate folder in your server

我建议将文件名保存在sql server表中,并将图像本身保存到服务器中的单独文件夹中

#2


0  

Currently you are using javascript to save the image, what control are you using to store the image? i.e. what is the AxeEyeCam control you have?

目前您使用javascript保存图像,您使用什么控件来存储图像?即你拥有的AxeEyeCam控件是什么?

If you can access this control from the Server-Side code then you should be able to read the image into a byte array and save this into SQL.

如果您可以从服务器端代码访问此控件,那么您应该能够将图像读入字节数组并将其保存到SQL中。

The following code uses a FileUpload control to read the data into a byte array

以下代码使用FileUpload控件将数据读入字节数组

byte[] bArray = new byte[fileUpImage.FileBytes().Length + 1];
int iBytesRead = fileUpImage.FileContent().Read(bArray, 0, fileUpImage.FileBytes().Length);

The following code then inserts this into a SQL table called TABLE :

然后,下面的代码将其插入名为TABLE的SQL表中:

try {
    System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(localConString);
    conn.Open();
    string insertStatement = "Insert Into [TABLE] ([IMAGE COLUMN]) VALUES (@Image)";

    System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(insertStatement, conn);
    cmd.Parameters.Add("@Image", System.Data.SqlDbType.Image);
    cmd.Parameters["@Image"].Value = bArray;
    double rdr = cmd.ExecuteNonQuery();

    conn.Close();
} catch (Exception ex) {
//Catches an error if one occurs

} finally {
    if (conn != null) {
        NewConn.Close();
    }
}

#1


1  

Here is the Steps

这是步骤

1- Create a web service and host it in a server ( the web service will contain a web method to upload your file and save it to a server)

1-创建Web服务并将其托管在服务器中(Web服务将包含用于上载文件并将其保存到服务器的Web方法)

2- Call the web service from your application ( Desktop application or web application )

2-从您的应用程序调用Web服务(桌面应用程序或Web应用程序)

Here is a Good Example for the web service and the client application

这是Web服务和客户端应用程序的一个很好的示例

http://www.c-sharpcorner.com/uploadfile/scottlysle/uploadwithcsharpws05032007121259pm/uploadwithcsharpws.aspx

http://www.c-sharpcorner.com/uploadfile/scottlysle/uploadwithcsharpws05032007121259pm/uploadwithcsharpws.aspx

I don't recommend saving the image as binary in the database because you may find it harder to retrieve and display

我不建议将图像保存为数据库中的二进制文件,因为您可能会发现它更难以检索和显示

I do recommend saving the file name in the sql server table and save the image itself to a separate folder in your server

我建议将文件名保存在sql server表中,并将图像本身保存到服务器中的单独文件夹中

#2


0  

Currently you are using javascript to save the image, what control are you using to store the image? i.e. what is the AxeEyeCam control you have?

目前您使用javascript保存图像,您使用什么控件来存储图像?即你拥有的AxeEyeCam控件是什么?

If you can access this control from the Server-Side code then you should be able to read the image into a byte array and save this into SQL.

如果您可以从服务器端代码访问此控件,那么您应该能够将图像读入字节数组并将其保存到SQL中。

The following code uses a FileUpload control to read the data into a byte array

以下代码使用FileUpload控件将数据读入字节数组

byte[] bArray = new byte[fileUpImage.FileBytes().Length + 1];
int iBytesRead = fileUpImage.FileContent().Read(bArray, 0, fileUpImage.FileBytes().Length);

The following code then inserts this into a SQL table called TABLE :

然后,下面的代码将其插入名为TABLE的SQL表中:

try {
    System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(localConString);
    conn.Open();
    string insertStatement = "Insert Into [TABLE] ([IMAGE COLUMN]) VALUES (@Image)";

    System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(insertStatement, conn);
    cmd.Parameters.Add("@Image", System.Data.SqlDbType.Image);
    cmd.Parameters["@Image"].Value = bArray;
    double rdr = cmd.ExecuteNonQuery();

    conn.Close();
} catch (Exception ex) {
//Catches an error if one occurs

} finally {
    if (conn != null) {
        NewConn.Close();
    }
}