当前位置: 首页>>代码示例>>Java>>正文


Java FormDataContentDisposition类代码示例

本文整理汇总了Java中org.glassfish.jersey.media.multipart.FormDataContentDisposition的典型用法代码示例。如果您正苦于以下问题:Java FormDataContentDisposition类的具体用法?Java FormDataContentDisposition怎么用?Java FormDataContentDisposition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FormDataContentDisposition类属于org.glassfish.jersey.media.multipart包,在下文中一共展示了FormDataContentDisposition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: uploadPdfFile

import org.glassfish.jersey.media.multipart.FormDataContentDisposition; //导入依赖的package包/类
@POST
@Path("/pdf")
@Consumes({MediaType.MULTIPART_FORM_DATA})
public Response uploadPdfFile(  @FormDataParam("file") InputStream fileInputStream,
                                @FormDataParam("file") FormDataContentDisposition fileMetaData) throws Exception
{
    String UPLOAD_PATH = "/tmp/upload/";
    try
    {
        int read = 0;
        byte[] bytes = new byte[1024];
 
        OutputStream out = new FileOutputStream(new File(UPLOAD_PATH + fileMetaData.getFileName()));
        while ((read = fileInputStream.read(bytes)) != -1)
        {
            out.write(bytes, 0, read);
        }
        out.flush();
        out.close();
    } catch (IOException e)
    {
        throw new WebApplicationException("Error while uploading file. Please try again !!");
    }
    return Response.ok("Data uploaded successfully !!").build();
}
 
开发者ID:zekaf,项目名称:jetty-nodes,代码行数:26,代码来源:UploadService.java

示例2: getUpload

import org.glassfish.jersey.media.multipart.FormDataContentDisposition; //导入依赖的package包/类
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public String getUpload(@FormDataParam("upload") InputStream inputStream,
    @FormDataParam("upload") FormDataContentDisposition header, @QueryParam("CKEditorFuncNum") int funcNum,
    @QueryParam("href") String href, @QueryParam("type") String type, @QueryParam("basehref") String basehref) {
    String path = "";
    try {
        path = saveFile(inputStream, href + "/" + header.getFileName());
    } catch (IOException e) {
        e.printStackTrace();
        return "";
    }
    if (type.equals("images")) {
        return "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction(" + funcNum + ",'"
            + path.substring(path.lastIndexOf("/") + 1, path.length()) + "', '');</script>";
    }
    return "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction(" + funcNum + ",'" + basehref
        + path.substring(path.lastIndexOf("/") + 1, path.length()) + "', '');</script>";
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:21,代码来源:MCRWCMSFileBrowserResource.java

示例3: uploadFile

import org.glassfish.jersey.media.multipart.FormDataContentDisposition; //导入依赖的package包/类
@POST
@Secured
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public UploadResponse uploadFile(@FormDataParam("file") InputStream uploadedInputStream,
		@FormDataParam("file") FormDataContentDisposition fileDetail) {
	
	if (uploadedInputStream == null || fileDetail == null)
		throw new RuntimeException("Invalid arguments");

	AttachmentContainer container =  attachmentManager.createAttachmentContainer();
	String uploadedFileLocation = container.getContainer() + "/" + fileDetail.getFileName();
	try {
		Files.copy(uploadedInputStream, Paths.get(uploadedFileLocation));
	} catch (IOException e) {
		logger.error("Error while saving file "+uploadedFileLocation, e);
		throw new RuntimeException("Error while saving file.");
	}
	UploadResponse response = new UploadResponse();
	response.setAttachmentId(container.getMeta().getId().toString());
	return response;
}
 
开发者ID:denkbar,项目名称:step,代码行数:23,代码来源:FileServices.java

示例4: post

import org.glassfish.jersey.media.multipart.FormDataContentDisposition; //导入依赖的package包/类
/**
 * @api {post} /picture/focus/:guid Attach a picture into a facus
 * @apiGroup Focus
 * 
 * @apiParam {String} guid Focus guid
 *
 * @apiParamExample {json} Request-Example:
 *     {
 *      "TODO": "TODO"
 *     }
 * 
 * @apiSuccessExample Success-Headers:
 *     HTTP/1.1 200 OK
 *
 * @apiSuccessExample Success-Response:
 *     {
 *       "TODO": "TODO"
 *     }
 */
@POST
@Consumes({ MediaType.MULTIPART_FORM_DATA })
@Produces("application/json;charset=UTF-8")
@Path("/focus/{focusguid}")
public Picture post(@PathParam("focusguid") String focusguid, @FormDataParam("file") InputStream fileInputStream,
        @FormDataParam("file") FormDataContentDisposition fileDisposition) {
    Focus focus = focusRepository.loadOrNotFound(focusguid);
    
    if (!user.getGuid().equals(focus.getAuthoruserguid())) {
        throw new BadRequestException("User does not own this item");
    }
    
    Picture picture = new Picture();
    picture.setGuid(UUID.randomUUID().toString());
    picture.setFilename(fileDisposition.getFileName());
    picture.setFocusGuid(focusguid);
    picture.setCreatedat(Long.toString(new Date().getTime()));
    
    pictureBucket.put(picture.getPath(), fileInputStream, fileDisposition.getSize());
    pictureRepository.save(picture);

    return picture;
}
 
开发者ID:coding4people,项目名称:mosquito-report-api,代码行数:43,代码来源:PictureController.java

示例5: create

import org.glassfish.jersey.media.multipart.FormDataContentDisposition; //导入依赖的package包/类
@Override
public void create(User user, Long projectId, InputStream uploadedInputStream,
                   FormDataContentDisposition fileDetail)
        throws IllegalStateException, IOException, NotFoundException {
    projectDAO.getByID(user.getId(), projectId); // access check

    Path uploadedDirectoryLocation = Paths.get(getUploadsDir(user, projectId));

    File uploadDirectory = uploadedDirectoryLocation.toFile();
    if (!uploadDirectory.exists()) {
        uploadDirectory.mkdir();
    }

    if (!uploadDirectory.isDirectory()) {
        throw new IllegalStateException("Could not find the right directory to upload the file.");
    }

    Path uploadedFileLocation = Paths.get(uploadedDirectoryLocation.toString(),
                                                        fileDetail.getFileName());

    if (uploadedFileLocation.toFile().exists()) {
        throw new IllegalStateException("The file already exists.");
    }

    writeToFile(uploadedInputStream, uploadedFileLocation.toString());
}
 
开发者ID:LearnLib,项目名称:alex,代码行数:27,代码来源:FileDAOImpl.java

示例6: shouldUploadAFile

import org.glassfish.jersey.media.multipart.FormDataContentDisposition; //导入依赖的package包/类
@Test
    public void shouldUploadAFile() {
        Path path = Paths.get(System.getProperty("user.dir"),
                              "src", "test", "resources", "rest", "IFrameProxyTestData.html");
        FileDataBodyPart filePart = new FileDataBodyPart("file", path.toFile());
        filePart.setContentDisposition(FormDataContentDisposition.name("file")
                                               .fileName("IFrameProxyTestData.html")
                                               .build());
        MultiPart multipartEntity = new FormDataMultiPart().bodyPart(filePart);
        Response response = target("/projects/" + PROJECT_TEST_ID + "/files")
                                .register(MultiPartFeature.class)
                                .request()
                                .post(Entity.entity(multipartEntity, MediaType.MULTIPART_FORM_DATA));
        System.out.println(" -> " + response.readEntity(String.class));
//        assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    }
 
开发者ID:LearnLib,项目名称:alex,代码行数:17,代码来源:FileResourceTest.java

示例7: multipartMapEcho

import org.glassfish.jersey.media.multipart.FormDataContentDisposition; //导入依赖的package包/类
/**
 * Echoes a multipart request including file content as a map of strings.
 *
 * @param multiPart
 * @return
 * @throws IOException
 */
@Path("/multipartMapEcho")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Map<String, String> multipartMapEcho(
        @DefaultValue("true") @FormDataParam("enabled") final boolean enabled,
        @FormDataParam("secret") final String secret,
        @FormDataParam("file") final InputStream file,
        @FormDataParam("file") final FormDataContentDisposition fileDisposition)
                throws IOException {
    final Map<String, String> echo = new HashMap<String, String>();
    echo.put("enabled", ObjectUtils.toString(enabled));
    echo.put("secret", secret);
    echo.put("file", IOUtils.toString(file));
    echo.put("filename", fileDisposition.getFileName());
    echo.put("filetype", fileDisposition.getType());
    return echo;
}
 
开发者ID:strandls,项目名称:alchemy-rest-client-generator,代码行数:26,代码来源:TestWebserviceMultipart.java

示例8: initializeFromXMLFile

import org.glassfish.jersey.media.multipart.FormDataContentDisposition; //导入依赖的package包/类
/**
 * Generates the attack graph and initializes the main objects for other API calls
 * (database, attack graph, attack paths,...).
 * Load the objects from the XML file POST through a form describing the whole network topology
 *
 * @param request             the HTTP request
 * @param uploadedInputStream The input stream of the XML file
 * @param fileDetail          The file detail object
 * @param body                The body object relative to the XML file
 * @return the HTTP response
 * @throws Exception
 */
@POST
@Path("/initialize")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response initializeFromXMLFile(@Context HttpServletRequest request,
                                      @FormDataParam("file") InputStream uploadedInputStream,
                                      @FormDataParam("file") FormDataContentDisposition fileDetail,
                                      @FormDataParam("file") FormDataBodyPart body) throws Exception {

    if (!body.getMediaType().equals(MediaType.APPLICATION_XML_TYPE) && !body.getMediaType().equals(MediaType.TEXT_XML_TYPE)
            && !body.getMediaType().equals(MediaType.TEXT_PLAIN_TYPE))
        return RestApplication.returnErrorMessage(request, "The file is not an XML file");
    String xmlFileString = IOUtils.toString(uploadedInputStream, "UTF-8");

    return initializeFromXMLText(request, xmlFileString);

}
 
开发者ID:fiware-cybercaptor,项目名称:cybercaptor-server,代码行数:29,代码来源:RestJsonAPI.java

示例9: addIDMEFAlerts

import org.glassfish.jersey.media.multipart.FormDataContentDisposition; //导入依赖的package包/类
/**
 * Receive alerts in IDMEF format and add them into a local queue file,
 * before releasing them when the client requests it.
 *
 * @param request             the HTTP request
 * @param uploadedInputStream The input stream of the IDMEF XML file
 * @param fileDetail          The file detail object
 * @param body                The body object relative to the XML file
 * @return the HTTP response
 * @throws Exception
 */
@POST
@Path("/idmef/add")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response addIDMEFAlerts(@Context HttpServletRequest request,
                               @FormDataParam("file") InputStream uploadedInputStream,
                               @FormDataParam("file") FormDataContentDisposition fileDetail,
                               @FormDataParam("file") FormDataBodyPart body) throws Exception {

    if (!body.getMediaType().equals(MediaType.APPLICATION_XML_TYPE) && !body.getMediaType().equals(MediaType.TEXT_XML_TYPE)
            && !body.getMediaType().equals(MediaType.TEXT_PLAIN_TYPE))
        return RestApplication.returnErrorMessage(request, "The file is not an XML file");

    String xmlFileString = IOUtils.toString(uploadedInputStream, "UTF-8");
    return addIDMEFAlertsFromXMLText(request, xmlFileString);
}
 
开发者ID:fiware-cybercaptor,项目名称:cybercaptor-server,代码行数:27,代码来源:RestJsonAPI.java

示例10: addOrUpdateNotifierInfo

import org.glassfish.jersey.media.multipart.FormDataContentDisposition; //导入依赖的package包/类
@PUT
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/notifiers/{id}")
@Timed
public Response addOrUpdateNotifierInfo(@PathParam("id") Long id,
                                        @FormDataParam("notifierJarFile") final InputStream inputStream,
                                        @FormDataParam("notifierJarFile") final FormDataContentDisposition contentDispositionHeader,
                                        @FormDataParam("notifierConfig") final FormDataBodyPart notifierConfig,
                                        @Context SecurityContext securityContext) throws IOException {
    SecurityUtil.checkPermissions(authorizer, securityContext, Notifier.NAMESPACE, id, WRITE);
    MediaType mediaType = notifierConfig.getMediaType();
    LOG.debug("Media type {}", mediaType);
    if (!mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) {
        throw new UnsupportedMediaTypeException(mediaType.toString());
    }
    Notifier notifier = notifierConfig.getValueAs(Notifier.class);
    String jarFileName = uploadJar(inputStream, notifier.getName());
    notifier.setJarFileName(jarFileName);
    Notifier newNotifier = catalogService.addOrUpdateNotifierInfo(id, notifier);
    return WSUtils.respondEntity(newNotifier, CREATED);
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:22,代码来源:NotifierInfoCatalogResource.java

示例11: addUDF

import org.glassfish.jersey.media.multipart.FormDataContentDisposition; //导入依赖的package包/类
/**
 * Add a new UDF.
 * <p>
 * curl -X POST 'http://localhost:8080/api/v1/catalog/udfs' -F udfJarFile=/tmp/foo-function.jar
 * -F udfConfig='{"name":"Foo", "description": "testing", "type":"FUNCTION", "className":"com.test.Foo"};type=application/json'
 * </p>
 */
@Timed
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/udfs")
public Response addUDF(@FormDataParam("udfJarFile") final InputStream inputStream,
                       @FormDataParam("udfJarFile") final FormDataContentDisposition contentDispositionHeader,
                       @FormDataParam("udfConfig") final FormDataBodyPart udfConfig,
                       @FormDataParam("builtin") final boolean builtin,
                       @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_UDF_ADMIN);
    MediaType mediaType = udfConfig.getMediaType();
    LOG.debug("Media type {}", mediaType);
    if (!mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) {
        throw new UnsupportedMediaTypeException(mediaType.toString());
    }
    UDF udf = udfConfig.getValueAs(UDF.class);
    processUdf(inputStream, udf, true, builtin);
    UDF createdUdf = catalogService.addUDF(udf);
    SecurityUtil.addAcl(authorizer, securityContext, UDF.NAMESPACE, createdUdf.getId(), EnumSet.allOf(Permission.class));
    return WSUtils.respondEntity(createdUdf, CREATED);
}
 
开发者ID:hortonworks,项目名称:streamline,代码行数:29,代码来源:UDFCatalogResource.java

示例12: uploadFile

import org.glassfish.jersey.media.multipart.FormDataContentDisposition; //导入依赖的package包/类
@Path("/file")
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(@DefaultValue("") @FormDataParam("tags") String tags,
		@FormDataParam("file") InputStream file,
		@FormDataParam("file") FormDataContentDisposition fileDisposition) {

	String fileName = fileDisposition.getFileName();

	saveFile(file, fileName);

	String fileDetails = "File saved at /Volumes/Drive2/temp/file/" + fileName + " with tags " + tags;

	System.out.println(fileDetails);

	return Response.ok(fileDetails).build();
}
 
开发者ID:geekmj,项目名称:jersey-jax-rs-examples,代码行数:18,代码来源:FileUploadResource.java

示例13: appendToDatabase

import org.glassfish.jersey.media.multipart.FormDataContentDisposition; //导入依赖的package包/类
/**
 * This method handles the upload of a TSV movie file and adds it to the
 * database
 * 
 * @param fileInputStream	the inputstream of the data (formdata)
 * @param contentDispositionHeader	Information about the transfered file
 * @return Status information if the import was successful
 */
@POST
@Path("/db/add")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
public String appendToDatabase(@FormDataParam("file") InputStream fileInputStream,
		@FormDataParam("file") FormDataContentDisposition contentDispositionHeader) {

	try {
		List<Movie> movies = DatabaseMovieImporter.importToDatabase(fileInputStream, adapter);
		return String.format("Success, inserted %d movies", movies.size());
	} catch (IOException e) {
		// TODO: do not return the error message (security)
		return e.getMessage();
	}

}
 
开发者ID:ratheile,项目名称:sweng15,代码行数:25,代码来源:MovieVisualizerAPI.java

示例14: importDatabase

import org.glassfish.jersey.media.multipart.FormDataContentDisposition; //导入依赖的package包/类
/**
 * This method handles the upload of a new TSV movie database
 * 
 * @param fileInputStream	the inputstream of the data (formdata)
 * @param contentDispositionHeader	Information about the transfered file
 * @return Status information if the import was successful
 */
@POST
@Path("/db/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
public String importDatabase(@FormDataParam("file") InputStream fileInputStream,
		@FormDataParam("file") FormDataContentDisposition contentDispositionHeader) {

	adapter.deleteDatabase();
	adapter.setupEmptyDatabase();

	try {
		List<Movie> movies = DatabaseMovieImporter.importToDatabase(fileInputStream, adapter);
		return String.format("Success, deleted database and inserted %d movies", movies.size());
	} catch (IOException e) {
		// TODO: do not return the error message (security)
		return e.getMessage();
	}
}
 
开发者ID:ratheile,项目名称:sweng15,代码行数:26,代码来源:MovieVisualizerAPI.java

示例15: simple

import org.glassfish.jersey.media.multipart.FormDataContentDisposition; //导入依赖的package包/类
@POST
@Path("/simple")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces("text/plain")
public String simple(@FormDataParam("upfile") String contentsAsString,
        @FormDataParam("upfile") InputStream fileStream,
        @FormDataParam("upfile") FormDataContentDisposition filecd)
        throws IOException {
    byte[] filedata = ByteStreams.toByteArray(fileStream);
    String hexdump = BaseEncoding.base16().lowerCase().encode(filedata);
    StringBuilder sb = new StringBuilder();
    sb.append("filedata=[" + contentsAsString + "]\r\n");
    sb.append("filename=[" + filecd.getFileName() + "]\r\n");
    sb.append("filesize=[" + filecd.getSize() + "]\r\n");
    sb.append("filetype=[" + filecd.getType() + "]\r\n");
    sb.append("hexdump=[" + hexdump + "]\r\n");
    return sb.toString();
}
 
开发者ID:msakamoto-sf,项目名称:jaxrs2-exercise-jersey-servlet,代码行数:19,代码来源:MultipartFormDataParametersDemoResource.java


注:本文中的org.glassfish.jersey.media.multipart.FormDataContentDisposition类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。