This topic is help to understand how to manage file name uses SQL Server and dynamic specific the client upload file name store in the server file system.
the purpose is save the file to the server file system without having the file name replicated problems. if client download the files from the server, the server can specify the file name depend which the real file name store in the server file system and a popup dialog on user browser with a file name specify from SQL server but not the physical file name store in the server file system.
Over write MIME protocol
When Internet Explorer receives the header, it raises a File Download dialog box whose file name box is automatically populated with the file name that is specified in the header.
For ASP .NET
Response.AddHeader("content-disposition","attachment; filename=fname.ext");
For JSP
response.setHeader( "Content-Disposition", "attachment; filename=" + downloadFileName );
Note:
- You may have to specify the Content Type resp.setContentType( "application/x-download" );
- Another Content-Type can instate of the content-disposition but it bahaves is differently
resp.setHeader( "Content-Type", "attachment; filename=" + downloadFileName );
For more information about content-disposition, see Request for Comments (RFC) 1806
http://support.microsoft.com/kb/260519
JSP Example
<%@ page language="java" contentType="text/html"%>
<%@ page import="java.io.*, java.util.*, javax.servlet.*"%>
<%
if (request.getParameter("filename").equals("") == false)
{
String path = request.getParameter("path");
String filename = request.getParameter("filename");
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=" + request.getParameter("filename"));
int iRead;
FileInputStream stream = null;
try
{
File f = new File(path + filename);
stream = new FileInputStream(f);
int ilength = 0;
while ((iRead = stream.read()) != -1)
{
out.write(iRead);
}
out.flush();
}
finally
{
if (stream != null)
{
stream.close();
}
}
}
%>