阅读:1370
回复:1
|
怎样在无登录的状态下载附件。
怎样在无登录的状态下载附件的方法,我应该调用什么方法可以直接下载,因为现在接口需要运用到。附件表里content字段保存的是什么格式的
|
1楼#
发布于:2020-06-02 15:42
保存的是二进制, 你可以写个后台代码, 读出来就行.
参考下啊: 页面里调用这个方法,传入附件ID , 会自动下载该文件 private void getFile(string attachmentID) { SqlCon con = new SqlCon("BPM"); string sqlstr = @"select Content as ByteData,FileName from OT_Attachment where ObjectID='" + attachmentID + "'"; try { con.open(); SqlDataReader dr = con.GetDataReader(sqlstr); if (dr.Read()) { int fileDataCol = 0; Byte[] b = new Byte[(dr.GetBytes(fileDataCol, 0, null, 0, int.MaxValue))]; string filename = Server.UrlEncode(dr.GetString(1)); dr.GetBytes(fileDataCol, 0, b, 0, b.Length); Response.ContentType = "Application/plain"; Response.AddHeader("Content-Disposition", "attachment; filename=" + filename); Response.Clear(); System.IO.Stream fs = Response.OutputStream; fs.Write(b, 0, b.Length); fs.Close(); Response.End(); } dr.Close(); } catch (Exception) { throw; } finally { con.close(); } } |
|