vbnet上传图片hel

时间:2013-06-03 19:06:30

标签: vb.net image upload

所以我曾经能够做到这一点,但忘了如何,因为我必须重新开始,它的部分

Dim bFile() As Byte = System.IO.File.ReadAllBytes(bmp)

这就是问题,我只是需要上传test.image甚至bmp(我保存的位图)或以某种方式从文件流上传图像,因为我不想保存到计算机磁盘......

        Dim clsRequest As System.Net.FtpWebRequest = _
DirectCast(System.Net.WebRequest.Create("ftp://ftp.myURL.info"), System.Net.FtpWebRequest)
        clsRequest.Credentials = New System.Net.NetworkCredential("myusername", "mypassword")
        clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
        ' read in file...         
        Dim bFile() As Byte = System.IO.File.ReadAllBytes(bmp)
        ' upload file...         
        Dim clsStream As System.IO.Stream = _
        clsRequest.GetRequestStream()
        clsStream.Write(bFile, 0, bFile.Length)
        clsStream.Close()
        clsStream.Dispose()

由于

1 个答案:

答案 0 :(得分:0)

试试这个:
插入图片:

Picturebox1.Image = New System.Drawing.Bitmap(New IO.MemoryStream(New System.Net.WebClient().DownloadData(UrlTOimg)))


上传图片:

Using ms As New System.IO.MemoryStream
    PictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
    Using wc As New System.Net.WebClient
        wc.UploadData("ftp://foo.com/bar/mumble.png", ms.ToArray())
    End Using
End Using

ftp url +密码:

ftp://username:password@ftp.website.com/htdocs/ImageName.png

享受=)