本文整理汇总了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();
}
示例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>";
}
示例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;
}
示例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;
}
示例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());
}
示例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());
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例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();
}
}
示例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();
}
}
示例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