本文整理汇总了Java中javax.ws.rs.core.MediaType.MULTIPART_FORM_DATA_TYPE属性的典型用法代码示例。如果您正苦于以下问题:Java MediaType.MULTIPART_FORM_DATA_TYPE属性的具体用法?Java MediaType.MULTIPART_FORM_DATA_TYPE怎么用?Java MediaType.MULTIPART_FORM_DATA_TYPE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.ws.rs.core.MediaType
的用法示例。
在下文中一共展示了MediaType.MULTIPART_FORM_DATA_TYPE属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFormPostResponse
protected final Response getFormPostResponse(String data,
String endpoint,
Class<? extends OutputStream> compressingClass,
String encoding) throws IOException {
byte[] bytes;
if (compressingClass == null) {
bytes = data.getBytes(StandardCharsets.UTF_8);
} else {
bytes = compress(data, compressingClass);
}
MediaType type =
encoding == null ? MediaType.TEXT_PLAIN_TYPE : new MediaType("application", encoding);
InputStream in = new ByteArrayInputStream(bytes);
StreamDataBodyPart filePart = new StreamDataBodyPart("data", in, "data", type);
try (MultiPart multiPart = new MultiPart(MediaType.MULTIPART_FORM_DATA_TYPE)) {
multiPart.getBodyParts().add(filePart);
return target(endpoint).request().post(
Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE));
}
}
示例2: uploadHomeFile
private void uploadHomeFile() throws Exception {
final FormDataMultiPart form = new FormDataMultiPart();
final FormDataBodyPart fileBody = new FormDataBodyPart("file", com.dremio.common.util.FileUtils.getResourceAsString("/testfiles/yelp_biz.json"), MediaType.MULTIPART_FORM_DATA_TYPE);
form.bodyPart(fileBody);
form.bodyPart(new FormDataBodyPart("fileName", "biz"));
com.dremio.file.File file1 = expectSuccess(getBuilder(getAPIv2().path("home/" + HOME_NAME + "/upload_start/").queryParam("extension", "json"))
.buildPost(Entity.entity(form, form.getMediaType())), com.dremio.file.File.class);
file1 = expectSuccess(getBuilder(getAPIv2().path("home/" + HOME_NAME + "/upload_finish/biz"))
.buildPost(Entity.json(file1.getFileFormat().getFileFormat())), com.dremio.file.File.class);
FileFormat fileFormat = file1.getFileFormat().getFileFormat();
assertEquals(physicalFileAtHome.getLeaf().getName(), fileFormat.getName());
assertEquals(physicalFileAtHome.toPathList(), fileFormat.getFullPath());
assertEquals(FileType.JSON, fileFormat.getFileType());
fileBody.cleanup();
}
示例3: formatChangeForUploadedHomeFile
@Test // DX-5410
public void formatChangeForUploadedHomeFile() throws Exception {
FormDataMultiPart form = new FormDataMultiPart();
FormDataBodyPart fileBody = new FormDataBodyPart("file", FileUtils.getResourceAsFile("/datasets/csv/pipe.csv"), MediaType.MULTIPART_FORM_DATA_TYPE);
form.bodyPart(fileBody);
form.bodyPart(new FormDataBodyPart("fileName", "pipe"));
doc("uploading a text file");
File file1 = expectSuccess(getBuilder(getAPIv2().path("home/" + HOME_NAME + "/upload_start/").queryParam("extension", "csv"))
.buildPost(Entity.entity(form, form.getMediaType())), File.class);
file1 = expectSuccess(getBuilder(getAPIv2().path("home/" + HOME_NAME + "/upload_finish/pipe"))
.buildPost(Entity.json(file1.getFileFormat().getFileFormat())), File.class);
final FileFormat defaultFileFormat = file1.getFileFormat().getFileFormat();
assertTrue(defaultFileFormat instanceof TextFileConfig);
assertEquals(",", ((TextFileConfig)defaultFileFormat).getFieldDelimiter());
doc("change the format settings of uploaded file");
final TextFileConfig newFileFormat = (TextFileConfig)defaultFileFormat;
newFileFormat.setFieldDelimiter("|");
final FileFormat updatedFileFormat = expectSuccess(getBuilder(getAPIv2().path("home/" + HOME_NAME + "/file_format/pipe"))
.buildPut(Entity.json(newFileFormat)), FileFormatUI.class).getFileFormat();
assertTrue(updatedFileFormat instanceof TextFileConfig);
assertEquals("|", ((TextFileConfig)updatedFileFormat).getFieldDelimiter());
}
示例4: testUploadExcelFile
private void testUploadExcelFile(final boolean isXLS) throws Exception {
final String extension = isXLS ? "xls" : "xlsx";
final FileType fileType = isXLS ? FileType.XLS : FileType.EXCEL;
FormDataMultiPart form = new FormDataMultiPart();
FormDataBodyPart fileBody = new FormDataBodyPart("file", FileUtils.getResourceAsFile("/testfiles/excel." + extension), MediaType.MULTIPART_FORM_DATA_TYPE);
form.bodyPart(fileBody);
form.bodyPart(new FormDataBodyPart("fileName", "excel"));
doc("uploading excel file");
File file1 = expectSuccess(getBuilder(getAPIv2().path("home/" + HOME_NAME + "/upload_start/").queryParam("extension", extension)).buildPost(
Entity.entity(form, form.getMediaType())), File.class);
file1 = expectSuccess(getBuilder(getAPIv2().path("home/" + HOME_NAME + "/upload_finish/excel")).buildPost(
Entity.json(file1.getFileFormat().getFileFormat())), File.class);
FileFormat file1Format = file1.getFileFormat().getFileFormat();
assertEquals("excel", file1Format.getName());
assertEquals(asList(HOME_NAME, "excel"), file1Format.getFullPath());
assertEquals(fileType, file1Format.getFileType());
fileBody.cleanup();
doc("getting a excel file");
File file2 = expectSuccess(getBuilder(getAPIv2().path("home/" + HOME_NAME + "/file/excel")).buildGet(), File.class);
FileFormat file2Format = file2.getFileFormat().getFileFormat();
assertEquals("excel", file2Format.getName());
assertEquals(asList(HOME_NAME, "excel"), file2Format.getFullPath());
assertEquals(fileType, file2Format.getFileType());
doc("querying excel file");
final JobsService jobsService = l(JobsService.class);
JobUI job = new JobUI(jobsService.submitJob(JobRequest.newBuilder()
.setSqlQuery(new SqlQuery("select * from \"" + HOME_NAME + "\".\"excel\"", SampleDataPopulator.DEFAULT_USER_NAME))
.build(), NoOpJobStatusListener.INSTANCE));
job.getData().loadIfNecessary();
JobDataFragment truncData = job.getData().truncate(500);
assertEquals(6, truncData.getReturnedRowCount());
assertEquals(5, truncData.getColumns().size());
doc("previewing excel file");
if (file2Format instanceof ExcelFileConfig) {
((ExcelFileConfig) file2Format).setExtractHeader(true);
} else {
((XlsFileConfig) file2Format).setExtractHeader(true);
}
JobDataFragment data = expectSuccess(getBuilder(getAPIv2().path("/home/" + HOME_NAME + "/file_preview/excel")).buildPost(Entity.json(file2Format)), JobDataFragment.class);
assertEquals(5, data.getReturnedRowCount());
assertEquals(5, data.getColumns().size());
doc("creating dataset from excel file");
InitialPreviewResponse previewResponse = expectSuccess(getBuilder(getAPIv2().path(
"/home/" + HOME_NAME + "/new_untitled_from_file/excel")).buildPost(Entity.json("")), InitialPreviewResponse.class);
assertEquals(5, previewResponse.getData().getColumns().size());
}