Changeset 2915


Ignore:
Timestamp:
Nov 15, 2006, 8:38:50 AM (16 years ago)
Author:
Nicklas Nordborg
Message:

Download servlet now sets a MIME type by checking the registered file extensions if no MIME type
is set on a file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/web/net/sf/basedb/clients/web/servlet/Download.java

    r2637 r2915  
    2525
    2626import net.sf.basedb.core.Application;
     27import net.sf.basedb.core.MimeType;
    2728import net.sf.basedb.core.SessionControl;
    2829import net.sf.basedb.core.DbControl;
     
    139140      dc = sc.newDbControl();
    140141      f = File.getByPath(dc, path, false);
     142      String mimeType = forceMimeType != null ? forceMimeType : f.getMimeType();
     143      if (mimeType == null)
     144      {
     145        mimeType = MimeType.getMimeType(dc, f.getName(), defaultMimeType);
     146      }
    141147      dc.close();
    142 
    143       String mimeType = forceMimeType != null ? forceMimeType : f.getMimeType();
    144       mimeType = mimeType != null ? mimeType : defaultMimeType;
    145148      response.setContentType(mimeType);
    146149      if (download) response.setHeader("Content-Disposition", "attachment;filename="+f.getName());
    147       response.setContentLength((int)f.getSize());
     150      if (f.getSize() < Integer.MAX_VALUE) response.setContentLength((int)f.getSize());
    148151      InputStream in = f.getDownloadStream(0);
    149152      OutputStream out = response.getOutputStream();
     
    152155      out.flush();
    153156      out.close();
    154       //Application.log("Download", "doGet", "file="+path+", MIME type="+mimeType+", bytes copied="+bytes);
    155 
    156157    }
    157158    catch (Exception ex)
    158159    {
    159       //Application.log("Download", "doGet", "exception="+ex+", path="+path);
    160160      throw new ServletException(ex);
    161161    }
Note: See TracChangeset for help on using the changeset viewer.