2012-03-03 16 views
5

मुझे 2 जीबी से बड़ी फ़ाइलों के साथ HTTP फ़ाइल अपलोड के साथ समस्याएं हैं। सर्वर और क्लाइंट दोनों 64 बिट हैं इसलिए सिस्टम परिप्रेक्ष्य से 2 जीबी का कोई प्रतिबंध नहीं होना चाहिए।टॉमकैट 6.0 बड़ी फ़ाइल अपलोड (> 2 जीबी)

  1. अपाचे LimitRequestBody = 0 (http://httpd.apache.org/docs/2.0/mod/core.html#LimitRequestBody)
  2. में बिलाव कनेक्टर maxPostSize में = 0 (http://tomcat.apache.org/tomcat-5.5-doc/config/ajp.html)

मैं Apache Commons फ़ाइल अपलोड उपयोग कर रहा हूँ: मैं निम्नलिखित किया था। मैंने ServerFileUpload setMaxFileSize विधि का उपयोग कर अधिकतम फ़ाइल आकार सेट करने का भी प्रयास किया।

मैं 2 जीबी से कम फ़ाइलों को अपलोड करने में सक्षम हूं (मैंने सफलतापूर्वक 1.88 जीबी फ़ाइल की कोशिश की)। कृपया मुझे निर्देशित करें, मैं यहां क्या खो रहा हूं?

जब बड़ी फ़ाइलों

यहाँ कोड का टुकड़ा है अपलोड करने और अधिक विशिष्ट ServletFileUpload.parseRequest विधि 0 FileItems रिटर्न होने के लिए:

if (isMultipartForm()) { 
try { 
    DiskFileItemFactory factory = new DiskFileItemFactory(); 
    factory.setSizeThreshold(SIZE_THRESHOLD);//SIZE_THRESHOLD = 4MB 
    ServletFileUpload upload = new ServletFileUpload(factory); 
     //upload.setFileSizeMax(3000000000L); Tried this too 
    upload.setProgressListener(progressListener); 
    items = upload.parseRequest(request); 
    if(items != null && items.size() == 0) 
    return new CommandResultSet(false, "NoItemsFoundInRequest"); 
    return new CommandResultSet(true, "" + ((items!=null) ? items.size() : "")); 
} catch(FileUploadException e) { 
    e.printStackTrace(); 
    System.out.println("Exception in MultipartFormManager. Can not parse request.");  
    return new CommandResultSet(false, e.getMessage()); 
    } 
} 
+0

आप अपाचे लाइब्रेरी का उपयोग कैसे कर रहे हैं? हमें कोड दिखाएं। –

+0

आपको किसी भी सर्वर समस्या को बाहर करने के लिए "wget" जैसे कच्चे कमांड लाइन टूल के साथ अपने सर्वर का परीक्षण करना चाहिए: फ़ाइल आकार सीमा में कहीं भी इंटीजर के रूप में एन्कोड किया गया है, फ़ाइल सिस्टम सीमा ... –

+0

आपकी समस्या के लक्षण क्या हैं? स्थानांतरण अटक गया है या बंद कर दिया गया है? कोई सर्वर स्टैक ट्रेस? "तार पर" गतिविधि के बारे में क्या - इसे वायरशर्क के साथ देखें। –

उत्तर

1

मैं निश्चित रूप से हो सकता है नया गलत है, लेकिन मैं नहीं मिला है कि यहां तक ​​कि 64 बिट ब्राउजर 2 जीबी से अधिक अपलोड अपलोड करते हैं। समस्या सर्वर नहीं है लेकिन ब्राउज़र है। आपको आश्चर्यजनक रूप से पर्याप्त मिलेगा कि अधिकांश आधुनिक ब्राउज़र एक मानक सर्वर से 2 जीबी से बड़ी फ़ाइलों को खुशी से डाउनलोड करेंगे, कोई विशेष कॉन्फ़िगरेशन आवश्यक नहीं है।

+0

क्या आप कृपया अपने उत्तर का समर्थन करने के लिए कोई लिंक प्रदान कर सकते हैं। मुझे केवल यह मिल सकता है (http://www.motobit.com/help/ScptUtl/pa33.htm) लेकिन मुझे विश्वास नहीं था। – Sunil

+0

हाय, संदर्भ के लिए धन्यवाद, इसके बारे में पता नहीं था। मेरी टिप्पणियां पिछले कुछ वर्षों में अपाचे 2.2, आईई और फ़ायरफ़ॉक्स के अनुभव पर आधारित हैं। क्रोम के बारे में सुनना अच्छा है, मैंने थोड़ी देर में इसका परीक्षण नहीं किया था। फ्लैश शायद आपकी मदद नहीं करेगा, आपको डेटा को इतनी बड़ी फाइल के सापेक्ष काफी छोटे टुकड़ों में भेजना होगा और चीजें बहुत धीमी हो जाएंगी। जब तक आप अपने क्लाइंट सॉफ़्टवेयर का उपयोग नहीं करते हैं, तब तक सभी वाणिज्यिक सेवाओं को मैं 2 जीबी से बड़ा नॉनपूपपोर्ट करने के बारे में जानता हूं। सही शीर्षलेख जानकारी के साथ, मुझे कोई कारण नहीं दिख रहा है कि अपाचे इन फ़ाइलों को कैसे संभाल नहीं सकता है। यह ब्राउज़र विकलांगता है। – Mike

+0

यहां [मोज़िला की बग प्रविष्टि का लिंक] है (https://bugzilla.mozilla.org/show_bug.cgi?आईडी = 215450) –

0

यदि आप उन आकारों के फ़ाइल अपलोड की अपेक्षा कर रहे हैं, तो मैं सीधे ब्राउज़र अपलोड पर भरोसा नहीं करता। एक जावा ऐपलेट या यहां तक ​​कि एक फ्लैश फ़ाइल (सुनिश्चित नहीं है कि संभव है, फ्लैश व्यक्ति नहीं) मेरी सिफारिश होगी, ताकि आप फ़ाइलों को टुकड़ों में तोड़ सकें। अगर अपलोड बाधित हो जाता है, तो आप इसे फिर से शुरू कर सकते हैं जहां से यह पिछली बार छोड़ा गया था।

+0

मैं समझता हूं कि यह विश्वसनीय नहीं है, लेकिन उस आकार के कम अनुरोध हैं, इसलिए यदि मैं कम से कम ऐसे अनुरोधों को संभाल सकता हूं तो यह बहुत अच्छा होगा। – Sunil

0
Jsp code : 
<script src="../lib/app/configurator.data.ajax.js" type="text/javascript"></script> 
<script src="../lib/ui/jquery.fileupload.js"></script> 
<html> 

<script language="Javascript"> 
var varb = ''; 
var test = 0; 
var count = 1; 
$(function() { 
var maxChunkSize = 30000000; //SET CHUNK SIZE HERE 
var your_global_var_for_form_submit = ''; 

var params = { 
     year: threeDSelectedYear, 
     series: threeDSelectedSeries 
}; 
/*File upload bind with form, 'fileupload' is my form id. As sumit triggers 
    for file ulaod will submit my form*/ 
/* replaceFileInput: true, */ 
$('#fileupload').fileupload({ 
maxChunkSize: maxChunkSize, 
url: efccustom.getEfcContext()+'upload/uploadZip?year='+threeDSelectedYear+'&series='+threeDSelectedSeries,    //URL WHERE FILE TO BE UPLOADED 
    error: function (jqXHR, textStatus, errorThrown) { 
    // Called for each failed chunk upload 
     $(".fileupload-loading").html(""); 
     $('.ANALYZE_DIALOG').dialog("close");  
    }, 

    success: function (data, textStatus, jqXHR) { 
    /*This event will be called on success of upload*/ 
    count = parseInt($('#counter').val()) + 1; 
    $('#counter').val(count); 

    $('#ttk').val(count); 
    data.ttk = 7; 
    console.log(" count ",count , data); 
    }, 

    submit: function (e, data) { 
    /*This event will be called on submit here i am 
        adding variable to form*/ 
    //console.log($('#zip_uploaded_file').val());  

    //console.log(data.originalFiles[0].name);    
    test = data.originalFiles[0]; 
    $('#fname').val(data.originalFiles[0].name); 
    $('#trequests').val(Math.ceil(data.originalFiles[0].size/maxChunkSize)); 
    $('#counter').val('1'); 
    }, 

    progress: function (e, data) { 
    /*PROGRESS BAR CODE WILL BE HERE */ 
     $(".fileupload-loading").html('<img src="../public/themeroller/images/throbber.gif" alt="Uploading Please Wait..." title="Uploading Please Wait...." />');  
    }, 

    add: function (e, data) { 
    $('.browsedFileName').html(data.originalFiles[0].name); 
    your_global_var_for_form_submit = data; 
    }, 

    done: function (e, data) { 

     ajaxcall.Data._get('upload/extractZipNCreateJson',params,function(data2) { 
      alert("file upload success "); 
      $(".fileupload-loading").html(""); 
      $('.ANALYZE_DIALOG').dialog("close"); 
     }); 


    } 

}); 
/*This is my button click event on which i am submitting my form*/ 
    $('#button').click(function(){ 
    your_global_var_for_form_submit.submit(); 
    }); 
}); 
</script> 

<html> 

<body> 


<form id="fileupload" enctype="multipart/form-data"> 
<div class="row fileupload-buttonbar"> 
<div class="span7"> 
<!--<input type="file" name="files" id="file" /> --> 

<input type="file" id="zip_uploaded_file" name="zip_uploaded_file" /> 
<input type="hidden" name="counter" id="counter" value="1" /> 
<input type="hidden" name="fname" id="fname" value="" /> 
<input type="hidden" name="trequests" id="trequests" value="1" /> 

<input type="hidden" name="ttk" id="ttk" value="1" /> 
<input type="button" id="button" name="button" value="submit" /> 
<span class='browsedFileName'></span> 
</div> 
</div> 
<!-- The loading indicator is shown during file processing --> 
<div class="fileupload-loading"></div> 
</form> 
</body> 


Controller COde : 
@RequestMapping(value = "/uploadZip", method = RequestMethod.POST, consumes = "multipart/form-data") 
    @ResponseBody 
    public ResponseEntity<String> 
    uploadZip(HttpServletRequest request, HttpServletResponse response) 
      throws IOException, IllegalArgumentException { 
     try {  
     String year = request.getParameter("year"); 
     String series = request.getParameter("series"); 
     log.info(" year " + year + " series " + series); 
     boolean isMultipart = ServletFileUpload.isMultipartContent(request); 
     if (isMultipart) { 

      FileItemFactory factory = new DiskFileItemFactory(); 
      ServletFileUpload upload = new ServletFileUpload(factory); 
      List items = upload.parseRequest(request); 
      Iterator iterator = items.iterator(); 

      HttpSession session = request.getSession(); 
      UserContext userContext = (UserContext) session 
        .getAttribute(ApplicationConstant.USER_CONTEXT); 
      String userName = userContext.getUser(); 
      String workSpaceInUse = userContext.getCurrentWorkSpace();   
      FileItem item = null; 
      boolean fileNotExistFlag; 
      String fileExtension; 
      while (iterator.hasNext()) { 
       item = (FileItem) iterator.next(); 

       String content = item.getContentType(); 
       log.info(" content "+content); 
       log.info(" File Type Getting Uploaded :"+content); 
       if (!item.isFormField()) { 
      /* Here in IOUtils the Third Parameter true tells that the small chunks of data that comes need to be added to the same File */ 
      IOUtils.copy(fileItem.getInputStream(), new FileOutputStream(new File(threeDPath+"/"+year+"/"+series+"/"+uploadZipFileName),true));    
       } 
      } 
      return null; 
     } 
     } 
     catch(Exception e) { 
      return handleError(new RuntimeException("Unexpected error while uploading ZIP", e)); 
     } 
     return null; 
    } 
1

यदि आप सामान्य-फ़ाइल अपलोड 1.1 या पुराने का उपयोग कर रहे हैं तो आप अधिकथन (1.9888) ~ 2 जीबी अपलोड नहीं कर सकते हैं। यहां समस्या यह है कि यह जार getContentLength नामक एक विधि को कॉल कर रहा है जो int प्रकार का है, इसलिए आपका अनुरोध केवल आकार को Integer.MAX_VALUE तक संभाल सकता है। सामान्य-फ़ाइल अपलोड के नवीनतम संस्करण में 1.3 की तरह यह हल हो गया था। उम्मीद है कि यह मदद करता है।

संबंधित मुद्दे