我现在FTP上传图片成功了,但是图片上传后必须在本地建立文件夹在从文件夹里面拿出图片在上传到FTP服务器,我现在想直接将上传的图片转成image对象直接上传FTP服务器,不在本地文件夹中存储了.这代码怎么做啊?public bool ftpupload_wap_img(System.Drawing.Image image, string uri)
{
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
reqFTP.Credentials = new NetworkCredential("test", "test");
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.UseBinary = true; //实例化流
MemoryStream imageStream = new MemoryStream();
//将图片的实例保存到流中
image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg);
//保存流的二进制数组
byte[] imageContent = new Byte[imageStream.Length]; imageStream.Position = 0;
//将流泻如数组中
imageStream.Read(imageContent, 0, (int)imageStream.Length);
byte[] buff = imageStream.ToArray();
try
{
Stream strm = reqFTP.GetRequestStream();
strm.Write(buff, 0, buff.Length);
strm.Close();
}
catch (Exception ex)
{
return false;
}
return true;
}这是我改的代码,图片上传后有此存转化的(image对象是此存转化后的对象),但是转成对应的尺寸后到FTP看不一样!
{
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
reqFTP.Credentials = new NetworkCredential("test", "test");
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.UseBinary = true; //实例化流
MemoryStream imageStream = new MemoryStream();
//将图片的实例保存到流中
image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg);
//保存流的二进制数组
byte[] imageContent = new Byte[imageStream.Length]; imageStream.Position = 0;
//将流泻如数组中
imageStream.Read(imageContent, 0, (int)imageStream.Length);
byte[] buff = imageStream.ToArray();
try
{
Stream strm = reqFTP.GetRequestStream();
strm.Write(buff, 0, buff.Length);
strm.Close();
}
catch (Exception ex)
{
return false;
}
return true;
}这是我改的代码,图片上传后有此存转化的(image对象是此存转化后的对象),但是转成对应的尺寸后到FTP看不一样!
解决方案 »
- asp.net关于长文章的分页问题。
- 限制别人浏览 网页 的次数
- 能否IIS回收和在cache消失之前捕获到这个cache中的值?
- openstmp如何写发送带有完整uri附件的邮件代码?
- string,byte[]和stream转变的问题,在线等
- 如何用vb script 改变一个层的显示和隐藏?
- 声明static方法和普通方法的区别有哪些?什么时候用?
- 几在C# 中,用什么方法可以判断1段字符串是否全为数字?是不是用正规表达式啊?怎样写啊?
- 请问如何删除服务器上指定文件夹下的文件/??
- 怎么实现不同用户登陆到不同页面?我使用了页面级的保护?
- 数据库事务Oracle .NET
- 怎么实现把数据库里的图片通过编辑的形式显示出来(代码如下高手来帮帮忙)
论坛签名======================================================================huhailong520:你好!
截至 2011-10-21 14:47:36 前:
你已发帖 23 个, 未结贴 0 个;
结贴率为: 100.00%
当您的问题得到解答后请及时结贴.
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html如何给分和结贴?
http://community.csdn.net/Help/HelpCenter.htm#结帖如何给自己的回帖中也加上签名?
http://blog.csdn.net/q107770540/archive/2011/03/15/6250007.aspx