图像上传到ASP.NET / VB中的Access DB = VOODOO WICHCRAFT要求???? [英] Image upload to Access DB in ASP.NET/VB = VOODOO WICHCRAFT REQUIRED????

查看:50
本文介绍了图像上传到ASP.NET / VB中的Access DB = VOODOO WICHCRAFT要求????的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在网上检查了大约80多个不同的上传脚本,包括

VB和C#,似乎没有人做我需要他们做的事情。也许有人在这里可以指出我还没到谷歌的地方(我已经走了

一直到谷歌的结果第50页!!) 。以下是我的要求:


a?¢我有一个DataGrid。一切都将从这里完成。一切。否

例外。一切都将在VB中完成,没有任何代码隐藏

来混淆像我这样的初学者。此外,不需要优化,

这个管理站点每月大约使用1-2次。可伸缩性和

性能不是问题。


a?¢新图像的上传将通过添加来完成。

数据网格的一行,在我的情况下是数据网格页脚,将由一个子页面处理,并带有e.commandname =" Insert"


a?¢图像将被上传,然后必须进行几次检查

才能将它们插入数据库。


a?¢首先检查:返回的流实际上是否包含任何内容?如果

没有,则添加数据库不能发生(必须有图像)。


a?¢秒检查:文件类型的返回流是image / jpeg吗?如果

没有,则添加到数据库不会发生(图像必须是jpeg)。


a?¢第三次检查:如果图像的任何尺寸超过640像素,它就是
需要按比例重新调整大小,每边最大尺寸640。

也就是说,800x600的图像将被碾压为640x480;一个400x800的图像

将被碾压为320x640。


a?¢第四次检查:如果图像的文件大小超过150kb,它将是

向下重采样,直到文件大小达到该值。


a?¢图像将与评论一起插入数据库

字段由< textarea />填充在数据网格中。


a?¢由于管理站点的数据网格是唯一需要

缩略图的地方(主站点没有),它需要一个showimage.aspx(可以

接受一个表名和一个来自Get字符串的唯一ID)重新调整

请求的图像(再次,按比例)在动态的方式之前,

图像会进入浏览器。所有缩略图的最大边长为100像素。这个重新调整大小必须在内部完成

showimage.aspx


下面是我到目前为止构建的SUB,但似乎是

将损坏的图像数据输入到DB中。无法提取图像,

即使使用高度简化的showimage.aspx:


Sub dgCarShowGalleryPhotos_Insert(发件人作为对象,e As

DataGridCommandEventArgs)

如果e.CommandName =" Insert"然后

Dim imgContent as Object = e.Item.Cells(2).Controls(1)

Dim strComment as String = CType(e.Item.Cells(3) .Controls(1),

Textbox).Text.Replace("''"," a ??")

Dim imgStream As Stream = imgContent .PostedFile.InputStream()

Dim imgType as String = imgContent.PostedFile.ContentType

Dim imgLen As Int64 = imgContent.PostedFile.ContentLength

Dim imgDimension as System.Drawing.Image =

System.Drawing.Image.FromStream(imgContent.PostedF ile.InputStream)

Dim imgHeight as String = imgDimension.PhysicalDimension.Height

Dim imgWidth as String = imgDimension.PhysicalDimension.Width

Dim imgbin()as Byte

如果不是imgStream什么都没有呢

如果imgContent.PostedFile.ContentLength> 0和

imgContent.PostedFile.ContentType =" image / jpeg"然后

如果imgWidth> 640或imgHeight> 640然后

imgbin = createThumbnail(imgStream,640,640)

Else

Dim imgBinaryData(imgLen)as Byte

Dim intStatus as Integer = imgStream.Read(imgBinaryData,0,imgLen)

imgBin = imgBinaryData

结束如果

CType(e。 Item.FindControl(" add_Comment"),TextBox).Text.Replace("''"," a ??")

Dim strSQL As String =" INSERT INTO [ tblCarShowGalleryPhotos]

([CarShowGalleryYearID],[图片],[评论])VALUES(&

Session(&IDHolder")&",@图片,@评论)"

Dim objConn as New

OleDbConnection(ConfigurationSettings.AppSettings(" strConn"))

objConn.Open ()

Dim myCommand为OleDbCommand = new OleDbCommand(strSQL,objConn)

myCommand.CommandType = CommandType.Text

Dim parameterImage as OleDbParameter =新的OleDbParameter(" @ Image",

OleDbType.Long VarBinary)

parameterImage.Value = imgBin

myCommand.Parameters.Add(parameterImage)

Dim parameterComment as OleDbParameter = new OleDbParameter(" @评论,

OleDbType.LongVarWChar)

parameterComment.Value = strComment

myCommand.Parameters.Add(parameterComment)

myCommand.ExecuteNonQuery()

objConn.Close()

dgCarShowGalleryPhotos.EditItemIndex = -1

BindData()

结束如果

结束如果

结束如果

结束子


这里是showimage.aspx文件,数据网格需要在任何地方引用

缩略图:


<%@ Page Language =" VB"调试= QUOT;真" %>

<%@ Import Namespace =" System" %>

<%@ Import Namespace =" System.Drawing" %>

<%@ Import Namespace =" System.Drawing.Imaging" %>

<%@ Import Namespace =" System.IO" %>

<%@ Import Namespace =" System.Data" %>

<%@ Import Namespace =" System.Data.OleDb" %>

< script runat = server>

Public Sub Page_Load(sender As Object,e As EventArgs)

Dim strTable as String = Request.QueryString(" table")

Dim strID as String = Request.QueryString(" id")

将myConn调暗为新

OleDbConnection(ConfigurationSettings.AppSettings(" strConn"))

将myCmd调暗为新的OleDbCommand(" SELECT [Image] FROM"& strTable&"

WHERE [ID] ="& strID,myConn)

myConn.Open()

将myDataReader调暗为OleDbDataReader =

myCmd .ExecuteReader(CommandBehavior.CloseConnectio n)

myDataReader.Read()

Dim imgStream(myDataReader.Item(" Image"))As System.IO.MemoryStream

Dim imgStream As System.IO.MemoryStream

imgStream = myDataReader.Item(" Image")

Dim imgbin as Array = createThumbnail(imgStream, 100,100)

Response.ContentType =& ; image / jpeg

Response.BinaryWrite(imgbin)

myConn.Close()

结束子

私有函数createThumbnail(ByVal ImageStream As Stream,ByVal

tWidth为Double,ByVal tHeight为Double)As Byte()

Dim g As System.Drawing.Image

= System.Drawing.Image.FromStream(ImageStream)

Dim thumbSize As New Size()

thumbSize = NewthumbSize(g.Width,g。高度,tWidth,tHeight)

Dim imgOutput As New Bitmap(g,thumbSize.Width,thumbSize.Height)

Dim imgStream As New MemoryStream()

Dim thisFormat = g.RawFormat

imgOutput.Save(imgStream,thisFormat)

Dim imgbin(imgStream.Length)As Byte

imgStream.Position = 0

Dim n As Int32 = imgStream.Read(imgbin,0,imgbin.Length)

g.Dispose()

imgOutput.Dispose()

返回imgbin

结束函数

函数NewthumbSize(ByVal currentwidth As Double,ByVal curr entheight

As Double,ByVal newWidth As Double,ByVal newHeight As Double)

Dim tempMultiplier As Double

if currentheight> currentwidth然后''肖像

tempMultiplier = newHeight / currentheight

否则

tempMultiplier = newWidth / currentwidth

结束If

Dim NewSize为新尺寸(CInt(currentwidth * tempMultiplier),

CInt(currentheight * tempMultiplier))

返回NewSize

结束功能

< / script>


它还会抛出一些非常糟糕的错误,特别是

信息是不兼容的类型。
字节的一维数组不能转换为字节类型等等。


再次,我想说互联网上没有任何内容

所有这些都与我正在尝试的相似创造。如果任何一个好的人可以帮助我找到适合该账单的东西,或者

纠正我所犯的任何错误,我会感激不尽。 />

TIA

... Geshel

-

********* ***************************************** ********* ***********

我的回复是一个自动监控的垃圾邮件蜜罐。除非你想被SpamCop列入黑名单,否则不要使用

。请以我的姓氏dot org回复我的第一个

名称。

********************* ***************************** ********************

I have examined about 80+ different upload scripts on the ''net, both in
VB and C#, and none seem to do what I need them to do. Perhaps someone
here can point me somewhere that Google hasn''t reached yet (I have gone
all the way to page 50 on Google''s results!!). Here are my requirements:

a?¢ I have a DataGrid. Everything will be done from here. Everything. No
exceptions. Everything will also be done in VB, without any code-behind
to confuse a beginner like me. Besides, optimization is not required,
this admin site will be used about 1-2 times a month. Scalability and
performance is NOT an issue.

a?¢ Uploading of new images will be done from the "add" line of the
datagrid, the datagrid footer in my case, and will be handled by a sub
with an e.commandname="Insert"

a?¢ The images are to be uploaded, and then several checks must be done
before they are inserted into the db.

a?¢ First Check: Does the returned stream actually contain anything? If
not, an "add" to the database cannot occur (there must be an image).

a?¢ Second Check: Is the returned stream of the filetype "image/jpeg"? If
not, the "add" to the database cannot occur (the image must be a jpeg).

a?¢ Third Check: If any dimension of the image exceeds 640 pixels, it
needs to be proportionally re-sized to a maximum size of 640 per side.
That is, an 800x600 image is to be crunched to 640x480; a 400x800 image
is to be crunched to 320x640.

a?¢ Fourth Check: If the file size of the image exceeds 150kb, it is to be
resampled downwards until the file size meets that value.

a?¢ The images are to be inserted into the database along with a comment
field populated by a <textarea /> in the datagrid.

a?¢ Since the datagrids of the Admin site is the only place that needs
thumbnails (the main site doesn''t), it needs a showimage.aspx (that can
accept a table name and a unique ID from the Get string) that re-sizes
the image requested (again, proportionally) in a dynamic manner before
the images make it to the browser. All thumbnails are to have a maximum
side length of 100 pixels. This re-sizing must be done inside the
showimage.aspx

Below is the SUB that I have managed to construct so far, but it seems
to input corrupted image data into the DB. Images can''t be extracted,
even with a highly simplified showimage.aspx:

Sub dgCarShowGalleryPhotos_Insert(sender As Object, e As
DataGridCommandEventArgs)
If e.CommandName = "Insert" Then
Dim imgContent as Object = e.Item.Cells(2).Controls(1)
Dim strComment as String = CType(e.Item.Cells(3).Controls(1),
Textbox).Text.Replace("''","a??")
Dim imgStream As Stream = imgContent.PostedFile.InputStream()
Dim imgType as String = imgContent.PostedFile.ContentType
Dim imgLen As Int64 = imgContent.PostedFile.ContentLength
Dim imgDimension as System.Drawing.Image =
System.Drawing.Image.FromStream(imgContent.PostedF ile.InputStream)
Dim imgHeight as String = imgDimension.PhysicalDimension.Height
Dim imgWidth as String = imgDimension.PhysicalDimension.Width
Dim imgbin() as Byte
If Not imgStream Is Nothing Then
If imgContent.PostedFile.ContentLength > 0 And
imgContent.PostedFile.ContentType = "image/jpeg" Then
If imgWidth > 640 Or imgHeight > 640 Then
imgbin = createThumbnail(imgStream, 640, 640)
Else
Dim imgBinaryData(imgLen) as Byte
Dim intStatus as Integer = imgStream.Read(imgBinaryData, 0, imgLen)
imgBin = imgBinaryData
End If
CType(e.Item.FindControl("add_Comment"), TextBox).Text.Replace("''","a??")
Dim strSQL As String = "INSERT INTO [tblCarShowGalleryPhotos]
([CarShowGalleryYearID], [Image], [Comment]) VALUES (" &
Session("IDHolder") & ", @Image, @Comment)"
Dim objConn as New
OleDbConnection(ConfigurationSettings.AppSettings( "strConn"))
objConn.Open()
Dim myCommand as OleDbCommand = new OleDbCommand(strSQL, objConn)
myCommand.CommandType = CommandType.Text
Dim parameterImage as OleDbParameter = new OleDbParameter("@Image",
OleDbType.LongVarBinary)
parameterImage.Value = imgBin
myCommand.Parameters.Add(parameterImage)
Dim parameterComment as OleDbParameter = new OleDbParameter("@Comment",
OleDbType.LongVarWChar)
parameterComment.Value = strComment
myCommand.Parameters.Add(parameterComment)
myCommand.ExecuteNonQuery()
objConn.Close()
dgCarShowGalleryPhotos.EditItemIndex = -1
BindData()
End If
End If
End If
End Sub

And here is the showimage.aspx file, which is referenced everywhere a
thumbnail is required by the datagrid:

<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script runat=server>
Public Sub Page_Load(sender As Object, e As EventArgs)
Dim strTable as String = Request.QueryString("table")
Dim strID as String = Request.QueryString("id")
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings( "strConn"))
Dim myCmd as New OleDbCommand("SELECT [Image] FROM " & strTable & "
WHERE [ID] = " & strID, myConn)
myConn.Open()
Dim myDataReader as OleDbDataReader =
myCmd.ExecuteReader(CommandBehavior.CloseConnectio n)
myDataReader.Read()
Dim imgStream(myDataReader.Item("Image")) As System.IO.MemoryStream
Dim imgStream As System.IO.MemoryStream
imgStream = myDataReader.Item("Image")
Dim imgbin as Array = createThumbnail(imgStream, 100, 100)
Response.ContentType="image/jpeg"
Response.BinaryWrite(imgbin)
myConn.Close()
End Sub
Private Function createThumbnail(ByVal ImageStream As Stream, ByVal
tWidth As Double, ByVal tHeight As Double) As Byte()
Dim g As System.Drawing.Image
=System.Drawing.Image.FromStream(ImageStream)
Dim thumbSize As New Size()
thumbSize =NewthumbSize(g.Width, g.Height, tWidth, tHeight)
Dim imgOutput As New Bitmap(g, thumbSize.Width, thumbSize.Height)
Dim imgStream As New MemoryStream()
Dim thisFormat = g.RawFormat
imgOutput.Save(imgStream, thisFormat)
Dim imgbin(imgStream.Length) As Byte
imgStream.Position = 0
Dim n As Int32 = imgStream.Read(imgbin, 0, imgbin.Length)
g.Dispose()
imgOutput.Dispose()
Return imgbin
End Function
Function NewthumbSize(ByVal currentwidth As Double, ByVal currentheight
As Double, ByVal newWidth As Double, ByVal newHeight As Double)
Dim tempMultiplier As Double
If currentheight > currentwidth Then '' portrait
tempMultiplier = newHeight / currentheight
Else
tempMultiplier = newWidth / currentwidth
End If
Dim NewSize As New Size(CInt(currentwidth * tempMultiplier),
CInt(currentheight * tempMultiplier))
Return NewSize
End Function
</script>

It also throws a number of very bad errors, particulary of the
information being of an incompatible type. "a 1-dimensional array of
byte cannot be converted to type of byte" and so forth.

Once again, I would like to say that there is NOTHING on the internet AT
ALL that is anywhere similar to what I am trying to create. If any of
you good ppl could help me find something that could fit the bill, or
correct any mistakes that I have made, I would be greatly indebted.

TIA
...Geshel
--
************************************************** ********************
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
************************************************** ********************

推荐答案

Neo,


据我所见,一切都很容易,除了部分你只需通过上传来命名




你能解释一下你的计划方式。


Cor
Neo,

As far as I can see, is everything easy to do, except the part you only name
by "upload".

Can you explain us how you have planned that.

Cor


小修正


*据我所见,一切都很容易做到*,但是没有

网页。


Cor
Little correction

* As far as I can see, is everything easy to do*, however not with a
webpage.

Cor


Cor Ligthert写道:
Cor Ligthert wrote:
Neo,

据我所见,一切都很容易,除了你只用上传命名
的部分。

你能解释一下吗?我们你是如何计划的那样。

Cor
Neo,

As far as I can see, is everything easy to do, except the part you only name
by "upload".

Can you explain us how you have planned that.

Cor




你在说什么* heck *?我的代码中没有任何内容

命名为upload。我只谈到了需要上传的内容。


或者,或许,你在谈论我讨论的第二个项目符号项目吗?b $ b谈论什么?


.... Geshel

-

****************** ******************************** ****************** **

我的回复是一个自动监控的垃圾邮件蜜罐。除非你想被SpamCop列入黑名单,否则不要使用

。请以我的姓氏dot org回复我的第一个

名称。

********************* ***************************** ********************



What the *heck* are you talking about?? There is nothing in my code
named "upload". I only talked about the need to upload.

Or, perchance, are you talking about the second bulleted item that I was
talking about?

....Geshel
--
************************************************** ********************
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
************************************************** ********************


这篇关于图像上传到ASP.NET / VB中的Access DB = VOODOO WICHCRAFT要求????的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆