Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DS-2359 Error when depositing large files via browser (over 2Gb) #1723

Merged
merged 1 commit into from Jul 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -7,29 +7,24 @@
*/
package org.dspace.app.xmlui.aspect.administrative;

import org.apache.cocoon.environment.Request;
import org.apache.cocoon.servlet.multipart.Part;
import org.apache.cocoon.servlet.multipart.PartOnDisk;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.dspace.app.itemimport.ItemImportServiceImpl;
import org.dspace.app.itemimport.factory.ItemImportServiceFactory;
import org.dspace.app.itemimport.service.ItemImportService;
import org.dspace.app.xmlui.wing.Message;
import org.dspace.authorize.AuthorizeException;
import java.io.*;
import java.sql.*;
import java.util.*;
import org.apache.cocoon.environment.*;
import org.apache.cocoon.servlet.multipart.*;
import org.apache.commons.io.*;
import org.apache.commons.lang.*;
import org.apache.log4j.*;
import org.dspace.app.itemimport.factory.*;
import org.dspace.app.itemimport.service.*;
import org.dspace.app.xmlui.cocoon.servlet.multipart.*;
import org.dspace.app.xmlui.wing.*;
import org.dspace.authorize.*;
import org.dspace.content.Collection;
import org.dspace.core.Context;
import org.dspace.core.LogManager;
import org.dspace.handle.HandleServiceImpl;
import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.handle.service.HandleService;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.dspace.handle.factory.*;
import org.dspace.handle.service.*;

/**
* Utility methods to processes BatchImport actions. These methods are used
Expand Down Expand Up @@ -97,7 +92,7 @@ public static FlowResult processUploadZIP(Context context, Request request) {

if (object instanceof Part) {
filePart = (Part) object;
file = ((PartOnDisk) filePart).getFile();
file = ((DSpacePartOnDisk) filePart).getFile();
}

if (filePart != null && filePart.getSize() > 0) {
Expand Down
Expand Up @@ -7,25 +7,19 @@
*/
package org.dspace.app.xmlui.aspect.administrative;

import java.io.IOException;
import java.sql.SQLException;
import java.io.File;
import java.util.List;

import org.apache.log4j.Logger;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.servlet.multipart.Part;
import org.apache.cocoon.servlet.multipart.PartOnDisk;
import org.dspace.app.bulkedit.BulkEditChange;
import org.dspace.app.bulkedit.DSpaceCSV;
import org.dspace.app.bulkedit.MetadataImport;
import org.dspace.app.bulkedit.MetadataImportException;
import org.dspace.app.bulkedit.MetadataImportInvalidHeadingException;
import org.dspace.app.xmlui.wing.Message;
import org.dspace.authorize.AuthorizeException;
import java.io.*;
import java.sql.*;
import java.util.*;
import org.apache.cocoon.environment.*;
import org.apache.cocoon.servlet.multipart.*;
import org.apache.log4j.*;
import org.dspace.app.bulkedit.*;
import org.dspace.app.xmlui.cocoon.servlet.multipart.*;
import org.dspace.app.xmlui.wing.*;
import org.dspace.authorize.*;
import org.dspace.core.Context;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.core.LogManager;
import org.dspace.services.factory.*;

/**
* Utility methods to processes MetadataImport actions. These methods are used
Expand Down Expand Up @@ -119,7 +113,7 @@ public static FlowResult processUploadCSV(Context context, Request request) thro
if (object instanceof Part)
{
filePart = (Part) object;
file = ((PartOnDisk)filePart).getFile();
file = ((DSpacePartOnDisk)filePart).getFile();
}

if (filePart != null && filePart.getSize() > 0)
Expand Down
Expand Up @@ -317,7 +317,7 @@ private void parseFilePart(DSpaceTokenStream in, Hashtable headers)
byte[] bytes = ((ByteArrayOutputStream) out).toByteArray();
this.parts.put(name, new PartInMemory(headers, bytes));
} else {
this.parts.put(name, new PartOnDisk(headers, file));
this.parts.put(name, new DSpacePartOnDisk(headers, file));
}
}

Expand Down
@@ -0,0 +1,99 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.app.xmlui.cocoon.servlet.multipart;

import java.io.*;
import java.util.*;
import org.apache.cocoon.servlet.multipart.*;

/**
* This class represents a file part parsed from a http post stream.
*
* @version $Id: PartOnDisk.java 587750 2007-10-24 02:35:22Z vgritsenko $
*/
public class DSpacePartOnDisk extends Part {

/** Field file */
private File file = null;
private int size;

/**
* Constructor PartOnDisk
*
* @param headers
* @param file
*/
public DSpacePartOnDisk(Map headers, File file) {
super(headers);
this.file = file;

// Ensure the file will be deleted when we exit the JVM
this.file.deleteOnExit();

this.size = file.length()>new Long(Integer.MAX_VALUE)?Integer.MAX_VALUE:((int) file.length());
}

/**
* Returns the file name
*/
public String getFileName() {
return file.getName();
}

/**
* Returns the file size in bytes
*/
public int getSize() {
return this.size;
}

/**
* Returns the file
*/
public File getFile() {
return file;
}

/**
* Returns a (ByteArray)InputStream containing the file data
*
* @throws IOException
*/
public InputStream getInputStream() throws IOException {
if (this.file != null) {
return new FileInputStream(file);
}
throw new IllegalStateException("This part has already been disposed.");
}

/**
* Returns the filename
*/
public String toString() {
return file.getPath();
}

/**
* Delete the underlying file.
*/
public void dispose() {
if (this.file != null) {
this.file.delete();
this.file = null;
}
}

/**
* Ensures the underlying file has been deleted
*/
public void finalize() throws Throwable {
// Ensure the file has been deleted
dispose();
super.finalize();
}
}