1

I'm doing an intranet for the employees of the company using ASP.NET and SQL Server, on the profile section i have an upload picture area (image field to show the picture, input to select the file, and the load button), this is working fine, the picture is loading into a folder, but, also i have the text fields where the user adds his info, this is also working great and is saving into the database, what now i want to do is that the user uploads the picture, and finish with all the text fields when he clicks the submit button to send all the fields into the database the name or the path of the picture he uploaded goes into the database too, all my textfields are being saved using an sqlDataSource with insertParameters.

Any idea how to do it?? i would prefer to do it with the front side code, since on the code behind i just have initializing the SqlDataSource1.Insert();

4

2 回答 2

1

不要将图像保存到磁盘,这样做迟早会导致丑陋的混乱。您应该做的是允许用户上传图像,在服务器上调整图像大小/裁剪图像,将图像转换为 base64 并将 base64 字符串保存到 varchar(max) 列中。

因为您只保存小图像(头像),所以这个解决方案应该没有任何问题。此外,当您从数据库中取回图像 base64 字符串时,如果不需要 IE7,您可以将其直接嵌入到 HTML 中。以下是支持数据 URI 方案的浏览器列表

如果无法将 base64 嵌入 HTML 中,请创建一个 ASP.NET 页面,将 base64 字符串解码为图像并返回二进制响应。然后像这样在您的页面中使用它:

<img src="http://www.example.com/images.aspx?thimageDBrowID=12345" width="20" height="20"/>
于 2012-07-09T20:28:13.253 回答
0

If you're using SQL Server 2008 you can look into using FILESTREAM

于 2012-07-09T20:39:50.593 回答