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


Java FormDataBodyPart类代码示例

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


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

示例1: upload

import com.sun.jersey.multipart.FormDataBodyPart; //导入依赖的package包/类
public void upload(String fileName, String sourceId,
		String fileTypeId, InputStream inputStream)
		throws ClientException {
	String path = UriBuilder
			.fromPath("/api/protected/file/upload/")
			.segment(sourceId)
			.segment(fileTypeId)
			.build().toString();
	FormDataMultiPart part = new FormDataMultiPart();
       part.bodyPart(
               new FormDataBodyPart(
                       FormDataContentDisposition
                               .name("file")
                               .fileName(fileName)
                               .build(),
                       inputStream, MediaType.APPLICATION_OCTET_STREAM_TYPE));
	doPostMultipart(path, part);
}
 
开发者ID:eurekaclinical,项目名称:eureka,代码行数:19,代码来源:EtlClient.java

示例2: doUploadFile

import com.sun.jersey.multipart.FormDataBodyPart; //导入依赖的package包/类
ClientResponse.Status doUploadFile(WebResource webResource, File file, String sourceId, String fileTypeId) throws ClientHandlerException, UniformInterfaceException, IOException {
	try (InputStream is = new FileInputStream(file)) {
		FormDataMultiPart part = 
				new FormDataMultiPart();
		part.bodyPart(
				new FormDataBodyPart(
						FormDataContentDisposition
								.name("file")
								.fileName(file.getName())
								.build(), 
						is, MediaType.APPLICATION_OCTET_STREAM_TYPE));
		ClientResponse response = webResource
				.path("/api/protected/file/upload/" + sourceId + "/" + fileTypeId)
				.type(MediaType.MULTIPART_FORM_DATA_TYPE)
				.post(ClientResponse.class, part);
		ClientResponse.Status result = response.getClientResponseStatus();
		return result;
	}
}
 
开发者ID:eurekaclinical,项目名称:eureka,代码行数:20,代码来源:FileUploadSupport.java

示例3: setFormParams

import com.sun.jersey.multipart.FormDataBodyPart; //导入依赖的package包/类
private static void setFormParams(FormDataMultiPart formData, Run run, String... excluded) throws IOException {
	Collection<String> ex = new HashSet<String>(Arrays.asList(excluded));
	Map<String,List<FormDataBodyPart>> formFields = formData.getFields();
	for (Map.Entry<String,List<FormDataBodyPart>> e : formFields.entrySet()) {
		String name = e.getKey();
		if (ex.contains(name)) {
			continue;
		}
		List<FormDataBodyPart> fields = e.getValue();
		if (fields.isEmpty()) {
			continue;
		}
		FormDataBodyPart field = fields.get(fields.size() - 1);
		if (name.startsWith(ParamValue.METHOD_UPLOAD + "-")) {
			name = name.substring(7);
			ContentDisposition cd = field.getContentDisposition();
			
			run.addUploadParamValue(name, cd.getFileName(), field.getValueAs(InputStream.class));
		}
		else {
			String value = field.getValue();
			setParam(run, name, value);
		}
	}
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:26,代码来源:RunLauncher.java

示例4: addFile

import com.sun.jersey.multipart.FormDataBodyPart; //导入依赖的package包/类
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_JSON })
public FileOutVO addFile(@FormDataParam("json") FormDataBodyPart json,
		@FormDataParam("data") FormDataBodyPart content,
		@FormDataParam("data") FormDataContentDisposition contentDisposition,
		@FormDataParam("data") final InputStream input) throws AuthenticationException, AuthorisationException, ServiceException {
	// in.setTrialId(trialId);
	// in.setModule(FileModule.TRIAL_DOCUMENT);
	// https://stackoverflow.com/questions/27609569/file-upload-along-with-other-object-in-jersey-restful-web-service
	json.setMediaType(MediaType.APPLICATION_JSON_TYPE);
	FileInVO in = json.getValueAs(FileInVO.class);
	FileStreamInVO stream = new FileStreamInVO();
	stream.setStream(input);
	stream.setMimeType(content.getMediaType().toString()); // .getType());
	stream.setSize(contentDisposition.getSize());
	stream.setFileName(contentDisposition.getFileName());
	return WebUtil.getServiceLocator().getFileService().addFile(auth, in, stream);
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:20,代码来源:FileResource.java

示例5: updateFile

import com.sun.jersey.multipart.FormDataBodyPart; //导入依赖的package包/类
@PUT
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_JSON })
public FileOutVO updateFile(@FormDataParam("json") FormDataBodyPart json,
		@FormDataParam("data") FormDataBodyPart content,
		@FormDataParam("data") FormDataContentDisposition contentDisposition,
		@FormDataParam("data") final InputStream input) throws AuthenticationException, AuthorisationException, ServiceException {
	// in.setId(fileId);
	json.setMediaType(MediaType.APPLICATION_JSON_TYPE);
	FileInVO in = json.getValueAs(FileInVO.class);
	FileStreamInVO stream = new FileStreamInVO();
	stream.setStream(input);
	stream.setMimeType(content.getMediaType().toString()); // .getType());
	stream.setSize(contentDisposition.getSize());
	stream.setFileName(contentDisposition.getFileName());
	return WebUtil.getServiceLocator().getFileService().updateFile(auth, in, stream);
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:18,代码来源:FileResource.java

示例6: updateInputField

import com.sun.jersey.multipart.FormDataBodyPart; //导入依赖的package包/类
@PUT
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_JSON })
public InputFieldOutVO updateInputField(@FormDataParam("json") InputFieldInVO in,
		@FormDataParam("data") FormDataBodyPart content,
		@FormDataParam("data") FormDataContentDisposition contentDisposition,
		@FormDataParam("data") final InputStream input) throws Exception {
	in.setDatas(CommonUtil.inputStreamToByteArray(input));
	in.setMimeType(content.getMediaType().toString());
	in.setFileName(contentDisposition.getFileName());
	return WebUtil.getServiceLocator().getInputFieldService().updateInputField(auth, in);
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:13,代码来源:InputFieldResource.java

示例7: extractInformation

import com.sun.jersey.multipart.FormDataBodyPart; //导入依赖的package包/类
/**
 * Extracts information from multipart form body part with given field name and puts it into passed
 * {@link RegistryFormData} object.
 * 
 * @param result
 *            registry information into which parsed information is saved.
 * @param field
 *            parsed field name.
 * @param part
 *            parsed multipart form body part.
 * @throws UnableToParseFormException
 *             should parsing the form and/or parameters passed in it fail.
 */
private void extractInformation(RegistryFormData result, String field, FormDataBodyPart part)
        throws UnableToParseFormException {
    if (field.equals(NAME)) {
        result.setName(getStringFromParam(part.getValue()));
    } else if (field.equals(LOCATION)) {
        result.setLocation(getStringFromParam(part.getValue()));
    } else if (field.equals(CERTIFICATE)) {
        result.setCertificate(extractInputFileSource(part));
    } else if (field.equals(DESCRIPTION)) {
        result.setDescription(getStringFromParam(part.getValue()));
    } else if (field.equals(READ_ENABLED)) {
        result.setReadEnabled(getBooleanFromParam(getStringFromParam(part.getValue())));
    } else if (field.equals(HARVESTED)) {
        result.setHarvested(getBooleanFromParam(getStringFromParam(part.getValue())));
    }
}
 
开发者ID:psnc-dl,项目名称:darceo,代码行数:30,代码来源:RegistryFormParser.java

示例8: extractInputFileSource

import com.sun.jersey.multipart.FormDataBodyPart; //导入依赖的package包/类
/**
 * Extracts certificate from the multipart form.
 * 
 * @param part
 *            parsed multipart form body part.
 * @return extracted certificate or <code>null</code> if empty field was passed.
 * @throws UnableToParseFormException
 *             should passed value be invalid.
 */
private byte[] extractInputFileSource(FormDataBodyPart part)
        throws UnableToParseFormException {
    ContentDisposition disp = part.getContentDisposition();
    if (disp.getFileName() != null) {
        InputStream is = part.getValueAs(InputStream.class);
        try {
            byte[] certificate = IOUtils.toByteArray(is);
            return certificate.length > 0 ? certificate : null;
        } catch (IOException e) {
            // fall through, error will be thrown nonetheless from the last line.
            logger.debug("IO error while parsing certificate data from multipart form: " + e.toString());
        }
    }
    throw new UnableToParseFormException("Could not parse the certificate information");
}
 
开发者ID:psnc-dl,项目名称:darceo,代码行数:25,代码来源:RegistryFormParser.java

示例9: getFileMapFromFormDataBodyPartList

import com.sun.jersey.multipart.FormDataBodyPart; //导入依赖的package包/类
protected Map<String, File> getFileMapFromFormDataBodyPartList(List<FormDataBodyPart> parts) {
	Map<String, File> files = new LinkedHashMap<String, File>();
	
	if (parts != null) {
		for (FormDataBodyPart part : parts) {
			String fileName = part.getContentDisposition().getFileName();
			File file = part.getValueAs(File.class);
			
			if (StringUtils.hasText(fileName) && file != null && file.canRead()) {
				files.put(fileName, file);
			}
		}
	}
	
	return files;
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:17,代码来源:AbstractRestServiceImpl.java

示例10: saveSpecificFile

import com.sun.jersey.multipart.FormDataBodyPart; //导入依赖的package包/类
/**
 * save file to folder on server
 * @param centralConfigService - central config service
 * @param formDataMultiPart - multi part  - file content
 * @param uploadDir - upload dir
 * @param fileName - file name
 */
public static void saveSpecificFile(CentralConfigService centralConfigService,
                                      FormDataMultiPart formDataMultiPart, String uploadDir, String fileName) {
    int fileUploadMaxSizeMb = centralConfigService.getMutableDescriptor().getFileUploadMaxSizeMb();
    // get uploaded file map
    Map<String, List<FormDataBodyPart>> fields = formDataMultiPart.getFields();
    fields.forEach((name, dataBody) -> {
        List<FormDataBodyPart> formDataBodyParts = fields.get(name);
            // get file name and data
            byte[] fileAsBytes = formDataBodyParts.get(0).getValueAs(byte[].class);
            if (FileUtils.bytesToMeg(fileAsBytes.length) > fileUploadMaxSizeMb && fileUploadMaxSizeMb > 0) {
                throw new BadRequestException("Uploaded file size is bigger than :" + fileUploadMaxSizeMb);
            }
            String fileLocation = uploadDir + File.separator + fileName;
            FileUtils.writeFile(fileLocation, fileAsBytes);
    });
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:24,代码来源:MultiPartUtils.java

示例11: post

import com.sun.jersey.multipart.FormDataBodyPart; //导入依赖的package包/类
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response post(
		@FormDataParam("file") InputStream file,
		@FormDataParam("file") FormDataContentDisposition fileDetail,
		@FormDataParam("file") FormDataBodyPart bodyPart,
		@FormDataParam("path") String path,
		@FormDataParam("draft") @DefaultValue("false") Boolean draft,
		@FormDataParam("overwrite") @DefaultValue("true") Boolean overwrite
		) throws Exception {
		
		Metadata fMeta = new Metadata();
		fMeta.setMimeType(bodyPart.getMediaType().toString());
		fMeta.setIsDir(false);
		fMeta.setName(fileDetail.getFileName());
		fMeta.setPath(path);

		fMeta = fileService.upload(file,fMeta,draft,overwrite);
		
		return Response.ok(fMeta).build();
	
}
 
开发者ID:josecoelho,项目名称:yep-rest-file-server,代码行数:23,代码来源:FilesRest.java

示例12: createAgreementMultipart

import com.sun.jersey.multipart.FormDataBodyPart; //导入依赖的package包/类
@Deprecated
@POST
@Path("agreements")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response createAgreementMultipart(@Context UriInfo uriInfo, FormDataMultiPart form,
        @QueryParam("agreementId") String agreementId) 
        throws ParserException, InternalException {
    
    FormDataBodyPart slaPart = form.getField("sla");
    String slaPayload = slaPart.getValueAs(String.class);

    String id = createAgreementImpl(agreementId, slaPayload);
    String location = buildResourceLocation(uriInfo.getAbsolutePath().toString() ,id);
    logger.debug("EndOf createAgreement");
    return buildResponsePOST(
            HttpStatus.CREATED,
            createMessage(HttpStatus.CREATED, id, 
                    "The agreement has been stored successfully in the SLA Repository Database. "
                    + "It has location " + location), location);
}
 
开发者ID:SeaCloudsEU,项目名称:SeaCloudsPlatform,代码行数:21,代码来源:SeacloudsRest.java

示例13: createPinAddForm

import com.sun.jersey.multipart.FormDataBodyPart; //导入依赖的package包/类
private FormDataMultiPart createPinAddForm(long boardID, String description, double price, String link, String imageUrl, File imageFile) {
	FormDataMultiPart multipartForm = new FormDataMultiPart();
	multipartForm.bodyPart(new FormDataBodyPart("board", Long.toString(boardID)));
	multipartForm.bodyPart(new FormDataBodyPart("details", description));
	multipartForm.bodyPart(new FormDataBodyPart("link", link));
	multipartForm.bodyPart(new FormDataBodyPart("csrfmiddlewaretoken", getAccessToken().getCsrfToken().getValue()));
	multipartForm.bodyPart(new FormDataBodyPart("buyable", ""));
	multipartForm.bodyPart(new FormDataBodyPart("tags", ""));
	multipartForm.bodyPart(new FormDataBodyPart("replies", ""));
	if(price != 0) {
		multipartForm.bodyPart(new FormDataBodyPart("buyable", "$" + Double.toString(price)));
	}
	if(imageUrl != null) {
		multipartForm.bodyPart(new FormDataBodyPart("img_url", imageUrl));
	}
	else {
		multipartForm.bodyPart(createImageBodyPart(imageFile));
	}
	return multipartForm;
}
 
开发者ID:redcraft,项目名称:pinterest4j,代码行数:21,代码来源:PinAPI.java

示例14: writeSourceFileToDisk

import com.sun.jersey.multipart.FormDataBodyPart; //导入依赖的package包/类
/**
 * Save uploaded file to specified location.
 * @param form
 * @return 
 * @throws IOException
 */
private String writeSourceFileToDisk(FormDataMultiPart form) throws IOException {
	FormDataBodyPart formFile = form.getField("file");
       String formName =  formFile.getContentDisposition().getFileName();
       
       String pathToTest = suggestName(formName);
	File file = new File(pathToTest);
	while (file.isFile()) {
        String lastExistingFile = pathToTest;
		pathToTest = getNewNameIfHashDiffers(formFile, pathToTest);
		if (pathToTest == null) { // file exists, same content
			return lastExistingFile;
		}
		file = new File(pathToTest);
	}
	
       InputStream readFormStream = formFile.getValueAs(InputStream.class);
	writeFile(readFormStream, file);
	
	return pathToTest;
}
 
开发者ID:AKSW,项目名称:LinkingLodPortal,代码行数:27,代码来源:UploadFileService.java

示例15: getNewNameIfHashDiffers

import com.sun.jersey.multipart.FormDataBodyPart; //导入依赖的package包/类
/**
 * Checks if the existing file has the same hash as the file from the form and renames if needed. If hash equals, existing name is used.
 * @param formFile
 * @param pathToTest
 * @return 
 * @throws IOException
 * @throws FileNotFoundException
 */
private String getNewNameIfHashDiffers(FormDataBodyPart formFile,
		String pathToTest) throws IOException, FileNotFoundException {
	InputStream hashFormStream = formFile.getValueAs(InputStream.class);

	String formHash = DigestUtils.md5Hex(hashFormStream);
	String diskHash = MD5Utils.computeChecksum(pathToTest);
	
	if (!formHash.equals(diskHash)) { // hash is different -> new name
		String nextTry = "";
		if (pathToTest.endsWith(".nt")) {
			nextTry = pathToTest.substring(0, pathToTest.length() - 3);
			nextTry = setNextName(nextTry);
			nextTry += ".nt";
		}
		else {
			nextTry = setNextName(nextTry);
		}
		
		return nextTry;
	}

	return null;
}
 
开发者ID:AKSW,项目名称:LinkingLodPortal,代码行数:32,代码来源:UploadFileService.java


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