MultiPart multipartEntity = new FormDataMultiPart() .field("emp", empPartJson, MediaType.APPLICATION_JSON_TYPE) .bodyPart(filePart);
public void upload(String url, String fileName) { InputStream stream = getClass().getClassLoader().getResourceAsStream(fileName); FormDataMultiPart part = new FormDataMultiPart().field("file", stream, MediaType.TEXT_PLAIN_TYPE); WebResource resource = Client.create().resource(url); String response = resource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(String.class, part); assertEquals("Hello, World", response); }
+ ""; MultiPart multipartEntity = new FormDataMultiPart() .field("emp", empPartJson, MediaType.APPLICATION_JSON_TYPE) .bodyPart(filePart);
public void testPostMultiPartFile() { final WebTarget target = target().path("test/multipart"); final FormDataMultiPart mp = new FormDataMultiPart(); final FormDataBodyPart p = new FormDataBodyPart("field1", "CONTENT ONE"); mp.bodyPart(p);
final MultiPart multiPart = formData ? new FormDataMultiPart() : new MultiPart();
public static UploadResponse uploadFile(WebTarget target, Path file, Path tagsFile) { assertThat(Files.exists(file), is(true)); // MediaType of the body part will be derived from the file. FileDataBodyPart filePart = new FileDataBodyPart("file", file.toFile(), MediaType.APPLICATION_OCTET_STREAM_TYPE); FormDataMultiPart mp = new FormDataMultiPart(); mp.bodyPart(filePart); if (tagsFile != null) { FileDataBodyPart tagsFilePart = new FileDataBodyPart("tags", tagsFile.toFile(), MediaType.APPLICATION_OCTET_STREAM_TYPE); mp.bodyPart(tagsFilePart); } if (staticLogger.isDebugEnabled()) { staticLogger.debug("Rest response: {}", restCall(target, "/_upload", mp, String.class, debugOption)); } return restCall(target, "/_upload", mp, UploadResponse.class, Collections.emptyMap()); } }
FormDataMultiPart multiPart = new FormDataMultiPart() .field("file", uploadedInputStream, MediaType.MULTIPART_FORM_DATA); Client client = ClientBuilder.newClient(); String url = "..."; Response response = client.target(url).request() .post(Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE)); String responseAsString = response.readEntity(String.class);
FormDataMultiPart p = new FormDataMultiPart(); p.bodyPart(new FormDataBodyPart(FormDataContentDisposition .name("fieldKey").fileName("document.pdf").build(), new File("path/to/document.pdf"), DefaultMediaTypePredictor.CommonMediaTypes .getMediaTypeFromFileName("document.pdf")));
final FormDataMultiPart formDataMultiPart = new FormDataMultiPart(); final String value = "Hello World"; final FormDataContentDisposition dispo = FormDataContentDisposition// .name("file")// .fileName("test.txt")// .size(value.getBytes().length)// .build(); final FormDataBodyPart bodyPart = new FormDataBodyPart(dispo, value); formDataMultiPart.bodyPart(bodyPart);
public FormBuilder(Map<String, String> map) { formData = new FormDataMultiPart(); for (Map.Entry<String, String> entry : map.entrySet()) { formData.field(entry.getKey(), entry.getValue()); } }
FormDataMultiPart form = new FormDataMultiPart(); URI uri = new File("filepath").toURI(); InputStream data = this.getClass().getResourceAsStream("filePath"); FormDataBodyPart fdp1 = new FormDataBodyPart("key1", uri.toString()); FormDataBodyPart fdp2 = new FormDataBodyPart("key2",data, MediaType.APPLICATION_OCTET_STREAM_TYPE); form.bodyPart(fdp1).bodyPart(fdp2); response = builder.post(ClientResponse.class, form); Assert.assertEquals(response.getStatus(), Status.OK.getStatusCode());
public Response uploadFile(final String file_path) { final FileDataBodyPart filePart = new FileDataBodyPart("file", new File(file_path)); final FormDataMultiPart multiPart = new FormDataMultiPart(); multiPart.bodyPart(filePart); final Response resp = fileUploadService.uploadFile(multiPart); return resp; } }
public boolean deploy(String archiveFile) { FileDataBodyPart archive = new FileDataBodyPart("id", new File(archiveFile)); MultiPart form = new FormDataMultiPart(). field("force", "true").bodyPart(archive); Response response = applicationTarget.request("application/json"). header("X-Requested-By", "loadr"). post(Entity.entity(form, form.getMediaType())); return (response.getStatus() == 200); }
public void uploadFile(String appName, File file) { FileDataBodyPart applicationPart = new FileDataBodyPart("file", file); MultiPart multipart = new FormDataMultiPart().bodyPart(applicationPart); Response response = post(uri, String.format(APPLICATIONS_FILES_PATH, appName), Entity.entity(multipart, multipart.getMediaType())); if (response.getStatus() != 200) { throw new ApiException(response); } }
private MultiPart computeMultiPart( Method method, Object[] parameter ) { FormDataMultiPart result = new FormDataMultiPart(); Annotation[][] parameterAnnotations = method.getParameterAnnotations(); for( int i = 0; i < parameterAnnotations.length; i++ ) { Annotation[] annotations = parameterAnnotations[ i ]; FormDataParam param = extractAnnotation( annotations, FormDataParam.class ); if( param != null ) { result.field( param.value(), parameter[ i ], determinePartContentType( parameter[ i ] ) ); } } return result.getFields().isEmpty() ? null : result; }
String url = "https://graph.facebook.com/me/photos"; File file = new File("path"); ClientConfig cc = new DefaultClientConfig(); cc.getClasses().add(MultiPartWriter.class); Client client = Client.create(cc); WebResource webResource = client.resource(url); FormDataMultiPart fdmp = new FormDataMultiPart(); fdmp.bodyPart(new FileDataBodyPart("source", file, MediaType.APPLICATION_OCTET_STREAM_TYPE)); fdmp.bodyPart(new FormDataBodyPart("message", "YAY I did it!")); fdmp.bodyPart(new FormDataBodyPart("access_token", accessToken)); ClientResponse response = webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(ClientResponse.class, fdmp); String string = response.getEntity(String.class);
ClientConfig cc = new DefaultClientConfig(); cc.getClasses().add(StringProvider.class);///////// here is the magic :) cc.getClasses().add(InputStreamProvider.class);//// cc.getClasses().add(MultiPartWriter.class);//////// WebResource webResource = Client.create(cc).resource("www......"); FormDataMultiPart multiPart = new FormDataMultiPart(); multiPart.field("bla", "bla bla", MediaType.APPLICATION_JSON_TYPE); ClientResponse response = webResource. type(MediaType.MULTIPART_FORM_DATA). post(ClientResponse.class,multiPart);
public static LensSessionHandle openSession(WebTarget target, final String userName, final String passwd, final LensConf conf, MediaType mt) { final WebTarget sessionTarget = target.path("session"); final FormDataMultiPart mp = new FormDataMultiPart(); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("username").build(), userName)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("password").build(), passwd)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionconf").fileName("sessionconf").build(), conf, mt)); return sessionTarget.request(mt).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), LensSessionHandle.class); }
public static FormDataMultiPart createFormDataMultiPartForFact(final LensSessionHandle sessionId, final XFactTable xFactTable, MediaType mt) { final FormDataMultiPart mp = new FormDataMultiPart(); mp.bodyPart(getSessionIdFormDataBodyPart(sessionId, mt)); mp.bodyPart(getFormDataBodyPart("fact", "fact", cubeObjectFactory.createXFactTable(xFactTable), mt)); return mp; }
private FormDataMultiPart getMultiFormData(String username, String password, MediaType mt) { final FormDataMultiPart mp = new FormDataMultiPart(); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("username").build(), username)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("password").build(), password)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionconf").fileName("sessionconf").build(), new LensConf(), mt)); return mp; }