其实 FTP 查看图片很简单, 首先我们要根据用户名, 密码, 还有服务器地址登录上 ftp 服务器.
然后把前端对应显示图片名称传到后台即可. 我前端显示图片是采用的 easyui 弹框, 其实只需一个 image 标签即可.
如下代码:
<div id="dlg">
<img src=""id="simg" />
</div>
js 代码
- function OclickAttachmentFile() {
- $('#dlg').dialog({
- title: '签证预览',
- width: 800,
- height:650,
- resizable:true,
- closed: false,
- cache: false,
- modal: true
- });
- var img = new Image();
- $(img).bind("load", function () {
- $("#simg").attr("src", this.src);
- });
- img.src = "/Common/file/GetFileUpload?fillName=" +
- '@Model.ErpPoMasterExtModel.DeliveryVoucherOriginName';
- }
- //<summary>
- // 获取文件
- //</summary>
- //<param name="fillName"> 图片名称 </param>
- //<returns> 图片流 </returns>
- public FileResult GetFileUpload(string fillName)
- {
- string usercConfig = ScmConfig.CusReceiptFtpUser; // 服务器用户名
- string pwdcConfig = ScmConfig.CusReceiptFtpPwd; // 服务器密码
- string ftpSrccConfig = ScmConfig.CustomerReceiptFtp; // 服务器地址
- FtpFileBase ftpFileBase = new FtpFileBase(usercConfig, pwdcConfig);
- FtpwebRequest request = (FtpWebRequest)WebRequest.Create(ftpSrccConfig + fillName);
- request.Method = WebRequestMethods.Ftp.DownloadFile;
- request.Credentials = new NetworkCredential(usercConfig, pwdcConfig);
- FtpWebResponse response = (FtpWebResponse)request.GetResponse();
- Stream responseStream = response.GetResponseStream();
- return File(responseStream, "image/jpeg");
- }
来源: http://www.bubuko.com/infodetail-2583926.html