uploadedFile = RESTUtils.handleEXTERNALUpload(getRequest());
}
else{
final StringBuilder builder =
new StringBuilder("Unrecognized file upload method: ").append(method);
throw new RestletException( builder.toString(), Status.CLIENT_ERROR_BAD_REQUEST);
}
}
catch (Throwable t) {
throw new RestletException( "Error while storing uploaded file:", Status.SERVER_ERROR_INTERNAL, t );
}
//handle the case that the uploaded file was a zip file, if so unzip it
if (mediaType!=null && RESTUtils.isZipMediaType( mediaType ) ) {
//rename to .zip if need be
if ( !uploadedFile.getName().endsWith( ".zip") ) {
File newUploadedFile = new File( uploadedFile.getParentFile(), uploadedFile.getName() + ".zip" );
uploadedFile.renameTo( newUploadedFile );
uploadedFile = newUploadedFile;
}
//unzip the file
try {
RESTUtils.unzipFile(uploadedFile, directory );
//look for the "primary" file
//TODO: do a better check
File primaryFile = findPrimaryFile( directory, format );
if ( primaryFile != null ) {
uploadedFile = primaryFile;
}
else {
throw new RestletException( "Could not find appropriate " + format + " file in archive", Status.CLIENT_ERROR_BAD_REQUEST );
}
}
catch( RestletException e ) {
throw e;
}
catch( Exception e ) {
throw new RestletException( "Error occured unzipping file", Status.SERVER_ERROR_INTERNAL, e );
}
}
return uploadedFile;