mirror of https://github.com/apache/archiva.git
use MultipartBody as a parameter for the FileUpload service and parse various parameters
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1307153 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
08002b92eb
commit
f832e697a0
|
@ -21,7 +21,10 @@ package org.apache.archiva.webapp.ui.services.api;
|
|||
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
|
||||
import org.apache.archiva.webapp.ui.services.model.FileMetadata;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.BooleanUtils;
|
||||
import org.apache.commons.lang.SystemUtils;
|
||||
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
|
||||
import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -70,6 +73,44 @@ public class DefaultFileUploadService
|
|||
}
|
||||
}
|
||||
|
||||
public FileMetadata post( MultipartBody multipartBody )
|
||||
throws ArchivaRestServiceException
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
String groupId =
|
||||
IOUtils.toString( multipartBody.getAttachment( "groupId" ).getDataHandler().getInputStream() );
|
||||
String artifactId =
|
||||
IOUtils.toString( multipartBody.getAttachment( "artifactId" ).getDataHandler().getInputStream() );
|
||||
String version =
|
||||
IOUtils.toString( multipartBody.getAttachment( "version" ).getDataHandler().getInputStream() );
|
||||
String packaging =
|
||||
IOUtils.toString( multipartBody.getAttachment( "packaging" ).getDataHandler().getInputStream() );
|
||||
|
||||
boolean generatePom = BooleanUtils.toBoolean(
|
||||
IOUtils.toString( multipartBody.getAttachment( "generatePom" ).getDataHandler().getInputStream() ) );
|
||||
|
||||
String classifier =
|
||||
IOUtils.toString( multipartBody.getAttachment( "classifier" ).getDataHandler().getInputStream() );
|
||||
|
||||
log.info( "uploading file:" + groupId + ":" + artifactId + ":" + version );
|
||||
Attachment file = multipartBody.getAttachment( "files[]" );
|
||||
File tmpFile = File.createTempFile( "upload-artifact", "tmp" );
|
||||
tmpFile.deleteOnExit();
|
||||
IOUtils.copy( file.getDataHandler().getInputStream(), new FileOutputStream( tmpFile ) );
|
||||
FileMetadata fileMetadata = new FileMetadata( "thefile", tmpFile.length(), "theurl" );
|
||||
fileMetadata.setDeleteUrl( tmpFile.getName() );
|
||||
return fileMetadata;
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new ArchivaRestServiceException( e.getMessage(),
|
||||
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Boolean deleteFile( String fileName )
|
||||
throws ArchivaRestServiceException
|
||||
{
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.archiva.webapp.ui.services.api;
|
|||
|
||||
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
|
||||
import org.apache.archiva.webapp.ui.services.model.FileMetadata;
|
||||
import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
|
||||
import org.codehaus.plexus.redback.authorization.RedbackAuthorization;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
|
@ -28,7 +29,6 @@ import javax.ws.rs.POST;
|
|||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
/**
|
||||
|
@ -39,15 +39,15 @@ import javax.ws.rs.core.MediaType;
|
|||
public interface FileUploadService
|
||||
{
|
||||
|
||||
//@Path( "upload" )
|
||||
@POST
|
||||
@Consumes( MediaType.MULTIPART_FORM_DATA )
|
||||
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||
@RedbackAuthorization( noRestriction = true )
|
||||
FileMetadata post( @QueryParam( "g" ) String groupId, @QueryParam( "a" ) String artifactId,
|
||||
@QueryParam( "v" ) String version, @QueryParam( "p" ) String packaging,
|
||||
@QueryParam( "c" ) String classifier, @QueryParam( "r" ) String repositoryId,
|
||||
@QueryParam( "generatePom" ) String generatePom )
|
||||
//FileMetadata post( @FormParam( "groupId" ) String groupId, @FormParam( "artifactId" ) String artifactId,
|
||||
// @FormParam( "version" ) String version, @FormParam( "packaging" ) String packaging,
|
||||
// @FormParam( "classifier" ) String classifier, @FormParam( "repositoryId" ) String repositoryId,
|
||||
// @FormParam( "generatePom" ) String generatePom )
|
||||
FileMetadata post( MultipartBody multipartBody )// @Multipart( value = "files[]", type = "*/*" ) Attachment file )
|
||||
throws ArchivaRestServiceException;
|
||||
|
||||
@Path( "{fileName}" )
|
||||
|
|
|
@ -27,7 +27,14 @@ define("archiva.artifacts-management",["jquery","i18n","order!utils","order!jque
|
|||
dataType: 'json',
|
||||
success: function(data) {
|
||||
mainContent.html($("#file-upload-tmpl" ).tmpl({managedRepositories: data}));
|
||||
$('#fileupload').fileupload();
|
||||
$('#fileupload').fileupload({
|
||||
add: function (e, data) {
|
||||
data.timeStamp = $.now();
|
||||
$.blueimpUI.fileupload.prototype
|
||||
.options.add.call(this, e, data);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@
|
|||
{% for (var i=0, file; file=o.files[i]; i++) { %}
|
||||
<tr class="template-upload">
|
||||
<td class="name"><span>{%=file.name%}</span></td>
|
||||
<td><input type="text" placeholder="classifier"></td>
|
||||
<td><input type="text" id="classifier" name="classifier" placeholder="classifier" value=""></td>
|
||||
<td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
|
||||
{% if (file.error) { %}
|
||||
<td class="error" colspan="2">
|
||||
|
|
Loading…
Reference in New Issue