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


Java FormDataContentDisposition.getFileName方法代码示例

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


在下文中一共展示了FormDataContentDisposition.getFileName方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: putFile

import org.glassfish.jersey.media.multipart.FormDataContentDisposition; //导入方法依赖的package包/类
/**
 * Endpoint for uploading arbitrary files of size up to 1024 Bytes.
 * @param uploadedInputStream The input stream containing the data.
 * @param fileDetails The details of the file to upload.
 * @return response indicating result of put operation.
 */
@Path("/files/{file}")
@PUT
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response putFile(
        @FormDataParam("file") InputStream uploadedInputStream,
        @FormDataParam("file") FormDataContentDisposition fileDetails
) {
    logger.info(fileDetails.toString());
    String fileName = fileDetails.getFileName();
    if (uploadedInputStream == null || fileName == null) {
        return ResponseUtils.plainResponse(NO_FILE_ERROR_MESSAGE, Response.Status.BAD_REQUEST);
    }

    if (fileDetails.getSize() > FILE_SIZE) {
       return ResponseUtils.plainResponse(UPLOAD_TOO_BIG_ERROR_MESSAGE, Response.Status.BAD_REQUEST);
    }

    try {
        logger.info("Storing {}", fileName);
        storeFile(stateStore, fileName, uploadedInputStream, fileDetails);
        return Response.status(Response.Status.OK).build();
    } catch (StateStoreException | IOException e) {
        logger.error("Failed to store file {}: {}", fileName, e);
        return Response.serverError().build();
    }
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:33,代码来源:StateResource.java

示例5: uploadFile

import org.glassfish.jersey.media.multipart.FormDataContentDisposition; //导入方法依赖的package包/类
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
public Response uploadFile(@FormDataParam("file") InputStream uploadedInputStream,
		@FormDataParam("file") FormDataContentDisposition fileDetail)// ,
{
	String uploadedFileLocation = paths.FileDirectory + fileDetail.getFileName();
	// save it
	writeToFile(uploadedInputStream, uploadedFileLocation);
	String output = "File uploaded to : " + uploadedFileLocation;
	return Response.status(200).entity(output).build();
}
 
开发者ID:MixedEmotions,项目名称:up_emotions_audio,代码行数:14,代码来源:EmoRecService.java

示例6: installExtras

import org.glassfish.jersey.media.multipart.FormDataContentDisposition; //导入方法依赖的package包/类
@POST
@Path("/stageLibraries/extras/{library}/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
@ApiOperation(value = "Install additional drivers", response = Object.class,
    authorizations = @Authorization(value = "basic"))
@RolesAllowed({AuthzRole.ADMIN, AuthzRole.ADMIN_REMOTE})
public Response installExtras(
    @PathParam("library") String library,
    @FormDataParam("file") InputStream uploadedInputStream,
    @FormDataParam("file") FormDataContentDisposition fileDetail
) throws IOException {
  String libsExtraDir = runtimeInfo.getLibsExtraDir();
  if (StringUtils.isEmpty(libsExtraDir)) {
    throw new RuntimeException(ContainerError.CONTAINER_01300.getMessage());
  }

  File additionalLibraryFile = new File(
      libsExtraDir + "/"	+ library + "/" + STAGE_LIB_JARS_DIR,
      fileDetail.getFileName()
  );
  File parent = additionalLibraryFile.getParentFile();
  if (!parent.exists()) {
    if (!parent.mkdirs()) {
      throw new RuntimeException(Utils.format("Failed to create directory: {}", parent.getName()));
    }
  }
  saveFile(uploadedInputStream, additionalLibraryFile);
  return Response.ok().build();
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:31,代码来源:StageLibraryResource.java

示例7: uploadFiles2

import org.glassfish.jersey.media.multipart.FormDataContentDisposition; //导入方法依赖的package包/类
@Path("/files")
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFiles2(@DefaultValue("") @FormDataParam("tags") String tags,
		@FormDataParam("files") List<FormDataBodyPart> bodyParts,
		@FormDataParam("files") FormDataContentDisposition fileDispositions,
		@FormDataParam("file2") InputStream file2,
		@FormDataParam("file2") FormDataContentDisposition fileDisposition2) {

	StringBuffer fileDetails = new StringBuffer("");

	/* Save multiple files */

	for (int i = 0; i < bodyParts.size(); i++) {
		/*
		 * Casting FormDataBodyPart to BodyPartEntity, which can give us
		 * InputStream for uploaded file
		 */
		BodyPartEntity bodyPartEntity = (BodyPartEntity) bodyParts.get(i).getEntity();
		String fileName = bodyParts.get(i).getContentDisposition().getFileName();

		saveFile(bodyPartEntity.getInputStream(), fileName);

		fileDetails.append(" File saved at /Volumes/Drive2/temp/file/" + fileName);
	}

	/* Save File 2 */

	String file2Name = fileDisposition2.getFileName();

	saveFile(file2, file2Name);
	fileDetails.append(" File saved at /Volumes/Drive2/temp/file/" + file2Name);
	fileDetails.append(" Tag Details : " + tags);

	System.out.println(fileDetails);

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

示例8: addDocument

import org.glassfish.jersey.media.multipart.FormDataContentDisposition; //导入方法依赖的package包/类
/**
 * Adds a new Document.
 * 
 * @return a NewDocumentResponse including the id of the new Document
 */
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public DocumentIdResponse addDocument(@FormDataParam("file") InputStream fileInputStream,
                                      @FormDataParam("file") FormDataContentDisposition fDispo,
                                      @FormDataParam("parameters") AnalysisParameters parameters) {
  if (parameters == null) {
    parameters = new AnalysisParameters();
  }

  Set<ConstraintViolation<AnalysisParameters>> violations =
      Validation.buildDefaultValidatorFactory().getValidator().validate(parameters);
  if (!violations.isEmpty()) {
    // TODO this does not work, it produces a generic Bad Request
    throw new ValidationViolationException(violations);
  }

  DocumentIdResponse response = null;
  
  String fileName = fDispo.getFileName();
  String baseName = FilenameUtils.getBaseName(fileName);
  String fileExtension = FilenameUtils.getExtension(fileName);
  Document document = createDocument(baseName);
  document.setParameters(parameters);
  String uuid = document.getContentID().toString();
  
  // set up path
  String filePath = DOCUMENT_PATH + baseName + "_" + uuid + "." + fileExtension;

  // check path and save file
  if (!checkAndCreateDir(DOCUMENT_PATH)) {
    throw new WebApplicationException("Can not save document!");
  } else {
    // save file on server
    saveFile(fileInputStream, filePath);

    document.setFilePath(new File(filePath).toPath());
    
    // schedule analysis
    String id = analysisController.scheduleDocumentAnalysis(document);

    // set up Response
    response = new DocumentIdResponse(id);
  }

  return response;
}
 
开发者ID:vita-us,项目名称:ViTA,代码行数:53,代码来源:DocumentsService.java


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