public static <T> T restCall(WebTarget target, String path, FormDataMultiPart mp, Class<T> clazz, Map<String, Object> params) { WebTarget targetPath = target.path(path); params.forEach(targetPath::queryParam); return targetPath.request(MediaType.MULTIPART_FORM_DATA) .accept(MediaType.APPLICATION_JSON) .post(Entity.entity(mp, mp.getMediaType()), clazz); }
@Override Entity<?> entity() { return Entity.entity(form, form.getMediaType()); }
Response response = builder.accept(MediaType.APPLICATION_JSON).put(Entity.entity(multiPart, multiPart.getMediaType()));
new FileDataBodyPart(name, fileToUpload); multiPart.bodyPart(filePart); final Entity<?> entity = Entity.entity(multiPart, Boundary.addBoundary(multiPart.getMediaType())); return (invocation(url, null).post(entity));
new FileDataBodyPart(name, fileToUpload); multiPart.bodyPart(filePart); final Entity<?> entity = Entity.entity(multiPart, Boundary.addBoundary(multiPart.getMediaType())); return (invocation(url, null).post(entity));
Response response = requestBuilder.post(Entity.entity(form, form.getMediaType()));
@Test public void testUploadDisabled() throws Exception { try { // disable uploads getSabotContext().getOptionManager().setOption(OptionValue.createBoolean(OptionValue.OptionType.SYSTEM, UIOptions.ALLOW_FILE_UPLOADS.getOptionName(), false)); 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")); expectStatus(Response.Status.FORBIDDEN, getBuilder(getAPIv2().path("home/" + HOME_NAME + "/upload_start/").queryParam("extension", "csv")).buildPost(Entity.entity(form, form.getMediaType()))); } finally { // re-enable uploads getSabotContext().getOptionManager().setOption(OptionValue.createBoolean(OptionValue.OptionType.SYSTEM, UIOptions.ALLOW_FILE_UPLOADS.getOptionName(), true)); } }
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); homeFileId = file1.getId(); FileFormat fileFormat = file1.getFileFormat().getFileFormat(); assertEquals(physicalFileAtHome.getLeaf().getName(), fileFormat.getName()); assertEquals(physicalFileAtHome.toPathList(), fileFormat.getFullPath()); assertEquals(FileType.JSON, fileFormat.getFileType()); fileBody.cleanup(); } }
@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()); }
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);
doc("upload file to staging"); File file1Staged = expectSuccess(getBuilder(getAPIv2().path("home/" + HOME_NAME + "/upload_start/").queryParam("extension", "json")).buildPost( Entity.entity(form, form.getMediaType())), File.class); FileFormat file1StagedFormat = file1Staged.getFileFormat().getFileFormat(); assertEquals("file1", file1StagedFormat.getName()); Entity.entity(form, form.getMediaType())), File.class); FileFormat file2StagedFormat = file2Staged.getFileFormat().getFileFormat();