图片上传错误 [英] Image uploading error

查看:141
本文介绍了图片上传错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们

我正在开发一个通过Web服务将图像上传并保存到数据库的应用程序.我有一个错误,这是下面的代码.错误:
类型字符串"的值不能转换为字节的一维数组".错误发生在下面以粗体突出显示的(Textbox1.Text)上.

您能帮我解决这个问题吗?

 受保护的  Button1_Click( ByVal 发​​件人 As  对象 ByVal  e  As  System.EventArgs)句柄 Button1.Click
         Dim  ws  As  新建 localhost.Service1( )
         Dim  data() As   Byte 
        数据= ws.ImageRetrieve (TextBox1.Text)
         Dim  As   New  FileStream(服务器. MapPath(Request.ApplicationPath)& " ,FileMode.Create)
        s.Write(data, 0 ,data.Length)
        s.Close()
        Image1.ImageUrl = Server.MapPath(Request.ApplicationPath)& " 

    结束  

解决方案

您尚未显示Web服务代码. ImageRetrieve方法将什么作为参数?我猜它不是字符串.


在ImageRetrieve的Web服务声明中,您必须将其编写为: Dim myText() As String ,而应编写为:Dim myText As String.
区别在于括号,这表示您希望myText是一个String数组(多个值,因此在分配值时需要一个索引).

只需删除ImageRetrieve方法中myText定义上的(),就可以解决您的问题.


非常感谢Sandeep,您的建议可以解决问题. >

Hi Guys

I am working on an application that would upload and save images to a database through web service. I am having an error, here''s my code below. The error :
value of type ''string'' cannot be converted to ''1-dimensional array of byte''. The error is happening on (Textbox1.Text) highlighted below in bold.

Can you please help me to solve this problem.

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ws As New localhost.Service1()
        Dim data() As Byte
        data = ws.ImageRetrieve(TextBox1.Text)
        Dim s As New FileStream(Server.MapPath(Request.ApplicationPath) & "\sample.jpg", FileMode.Create)
        s.Write(data, 0, data.Length)
        s.Close()
        Image1.ImageUrl = Server.MapPath(Request.ApplicationPath) & "\sample.jpg"

    End Sub

解决方案

You have not shown the webservice code. What does ImageRetrieve method take as a paramater? I''m guessing it isn''t a string.


In your webservice declaration for ImageRetrieve, you must have written it as: Dim myText() As String when you should have written: Dim myText As String.
The difference is that parenthesis, which indicate that you want myText to be a String array (more than one value and therefore needing an index when assigning values).

Just take away the () on the myText definition in ImageRetrieve method and your issue should be resolved.


Thank you veru much Sandeep, your suggestion did the trick.


这篇关于图片上传错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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