فايرفوكس تخفيضات الملفات التي تحتوي على مسافات في تطبيق الدعامات

StackOverflow https://stackoverflow.com/questions/177863

  •  05-07-2019
  •  | 
  •  

سؤال

أنا باستخدام الدرس القادم (المبسطة أجل فهمها) لتحميل الصور في الدعامات تطبيق ويب.فمن يعمل في كل متصفح ولكن فايرفوكس ، الذي يقطع الأسماء التي تحتوي على مسافات.أنه يقول: الملف مع المساحات.pdf يحصل تحميلها في فايرفوكس مثل: الملف بينما في كروم ، IE6 IE7 هو تحميلها كما الملف مع المساحات.pdf.

public class Download extends Action {
    private static final int BUFFER_SIZE = 4096;    

    public ActionForward execute(ActionMapping mapping,
        ActionForm     form,
        HttpServletRequest request,
        HttpServletResponse response) throws Exception {
        String filename = "file with spaces.pdf";
        File file =  ... // variable containing the file;
        response.setStatus(HttpServletResponse.SC_OK);
        response.setContentType(getMimeType(request, file));
        response.setHeader("Content-Type", getMimeType(request, file));
        response.setHeader("Content-Disposition","attachment; filename="+ filename);
        InputStream is = new FileInputStream(file); 
        sendFile(is, response);
        return null;
   }  

   protected String getMimeType(HttpServletRequest request, File file) {
        ServletContext application = super.servlet.getServletContext();
        return application.getMimeType(file.getName());
   }

   protected void sendFile(InputStream is, HttpServletResponse response) throws IOException {
       BufferedInputStream in = null;
       try {
            int count;
            byte[] buffer = new byte[BUFFER_SIZE];
            in = new BufferedInputStream(is);
            ServletOutputStream out = response.getOutputStream();
            while(-1 != (count = in.read(buffer)))
                out.write(buffer, 0, count);
            out.flush();            
       } catch (IOException ioe) { 
            System.err.println("IOException in Download::sendFile"); 
            ioe.printStackTrace();
       } finally {
            if (in != null) {
                try { 
                   in.close(); 
                } catch (IOException ioe) { ioe.printStackTrace(); }
            }   
       }
    }
}

لا أحد يعرف عن ماذا يجري هنا ؟ ملاحظة: أنا أستخدم firefox 3.0.3 تحت ويندوز فيستا.

هل كانت مفيدة؟

المحلول

اسم الملف يجب أن يكون نقلت السلسلة.(وفقا القسم 19.5.1 RFC 2616)

response.setHeader("Content-Disposition","attachment; filename=\"" + filename + "\"");

نصائح أخرى

URLEncode اسم الملف?

أو على الأقل بديل %20 الفضاء الشخصية.

(أنا لا أعرف إذا كان هذا العمل ، ولكن المحاولة)

هل حاولت فقط وضع علامات الاقتباس حول اسم الملف ؟

هذا هو ميزة الأمان من فايرفوكس 3 على ما أعتقد.

ها نحن ذا

http://support.mozilla.com/tiki-view_forum_thread.php?locale=no&forumId=1&comments_parentId=91513

انها مختلفة ولكن قد تساعد :)

الاستمتاع

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top