added check on file size (allowed 100mb at most)
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/catalogue-ws@146529 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
9ef3e69298
commit
9093618785
|
@ -1,5 +1,6 @@
|
|||
package org.gcube.datacatalogue.catalogue.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -47,6 +48,7 @@ import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataFormat;
|
|||
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataGrouping;
|
||||
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataTagging;
|
||||
import org.geojson.GeoJsonObject;
|
||||
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
|
||||
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||
import org.json.simple.JSONArray;
|
||||
|
@ -83,6 +85,7 @@ public class CatalogueUtils {
|
|||
public static final String VERSION_KEY = "version";
|
||||
public static final String SEPARATOR_MULTIPLE_VALUES_FIELD = ",";
|
||||
public static final int MAX_TAG_CHARS = 100;
|
||||
public static final short MAX_UPLOADABLE_FILE_SIZE_MB = 100;
|
||||
|
||||
|
||||
// =======================================================================
|
||||
|
@ -1015,7 +1018,19 @@ public class CatalogueUtils {
|
|||
|
||||
// use jersey client
|
||||
logger.trace("Sending multipart to CKAN " + multiPart);
|
||||
|
||||
|
||||
FormDataBodyPart upload = multiPart.getField("upload");
|
||||
if(upload != null){
|
||||
File file = upload.getValueAs(File.class);
|
||||
long fileLenghtBytes = file.length();
|
||||
long fileLenghtMegaByte = fileLenghtBytes/(1024 * 1024) ;
|
||||
logger.trace("File lenght in MegaByte is " + fileLenghtMegaByte);
|
||||
|
||||
if(fileLenghtMegaByte > MAX_UPLOADABLE_FILE_SIZE_MB)
|
||||
throw new Exception("Exceeding maximum uploadable file size!");
|
||||
|
||||
}
|
||||
|
||||
Client client = ClientBuilder.newClient();
|
||||
client.register(MultiPartFeature.class);
|
||||
WebTarget webResource = client.target(requestPath);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.gcube.datacatalogue.catalogue.ws;
|
||||
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
|
@ -51,7 +52,8 @@ public class Resource {
|
|||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String create(
|
||||
FormDataMultiPart multiPart, @Context UriInfo uriInfo
|
||||
FormDataMultiPart multiPart, @Context UriInfo uriInfo,
|
||||
@Context final HttpServletRequest request
|
||||
){
|
||||
|
||||
// see http://docs.ckan.org/en/latest/api/#ckan.logic.action.create.resource_create
|
||||
|
|
Reference in New Issue