List of usage examples for org.springframework.http MediaType MULTIPART_FORM_DATA
MediaType MULTIPART_FORM_DATA
To view the source code for org.springframework.http MediaType MULTIPART_FORM_DATA.
Click Source Link
From source file:eu.falcon.semantic.client.DenaClient.java
public static String publishOntology(String fileClassPath, String format, String dataset) { RestTemplate restTemplate = new RestTemplate(); LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>(); final String uri = "http://localhost:8090/api/v1/ontology/publish"; //final String uri = "http://falconsemanticmanager.euprojects.net/api/v1/ontology/publish"; map.add("file", new ClassPathResource(fileClassPath)); map.add("format", format); map.add("dataset", dataset); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); HttpEntity<LinkedMultiValueMap<String, Object>> entity = new HttpEntity<LinkedMultiValueMap<String, Object>>( map, headers);//from w ww . jav a 2s . c om String result = restTemplate.postForObject(uri, entity, String.class); return result; }
From source file:eu.falcon.semantic.client.DenaClient.java
public static String addInstances(String fileClassPath, String format) { RestTemplate restTemplate = new RestTemplate(); LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>(); //final String uri = "http://localhost:8090/api/v1/ontology/instances/publish"; final String uri = "http://falconsemanticmanager.euprojects.net/api/v1/ontology/instances/publish"; map.add("file", new ClassPathResource(fileClassPath)); map.add("format", format); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); HttpEntity<LinkedMultiValueMap<String, Object>> entity = new HttpEntity<LinkedMultiValueMap<String, Object>>( map, headers);// www . j a v a 2s.c o m String result = restTemplate.postForObject(uri, entity, String.class); return result; }
From source file:guru.nidi.ramltester.FormTest.java
@Test public void multipartForm() throws Exception { assertNoViolations(test(aggregator, form, fileUpload("/form/multi").file("file", new byte[] { 1, 2, 3 }) .contentType(MediaType.MULTIPART_FORM_DATA).param("param", "a +b"), jsonResponse(200, "", null))); }
From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.AppBitsUploadingStepTest.java
private HttpEntity<MultiValueMap<String, Object>> createTestAppBitsRequest() throws IOException { HttpEntity<String> resourcesPart = new HttpEntity<String>("[]"); HttpEntity<ByteArrayResource> dataPart = new HttpEntity<>( new ByteArrayResource(Files.readAllBytes(testAppBitsPath)), HttpCommunication.zipHeaders()); MultiValueMap<String, Object> multiPartRequest = new LinkedMultiValueMap<>(); multiPartRequest.add("resources", resourcesPart); multiPartRequest.add("application", dataPart); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); return new HttpEntity<>(multiPartRequest, headers); }
From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.AppBitsUploadingStep.java
/** * Prepares request to CF//from ww w. j a va2s. co m * <a href="https://apidocs.cloudfoundry.org/225/apps/uploads_the_bits_for_an_app.html">endpoint * </a> * * @param dataPath * @return prepared request * @throws IOException */ private HttpEntity<MultiValueMap<String, Object>> prepareMutlipartRequest(Path dataPath) throws IOException { HttpEntity<String> resourcesPart = prepareResourcesRequestPart(); HttpEntity<ByteArrayResource> dataPart = prepareDataRequestPart(dataPath); MultiValueMap<String, Object> multiPartRequest = new LinkedMultiValueMap<>(); multiPartRequest.add("resources", resourcesPart); multiPartRequest.add("application", dataPart); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); return new HttpEntity<>(multiPartRequest, headers); }
From source file:com.ezsource_mobile.fileservice.FileService.java
public FileUploadResponse[] uploadFile(final MultipartFile[] files, final String relativePath, final HttpServletRequest httpServletRequest) { LOGGER.debug("start of uploadFile method"); final RestTemplate restTemplate = new RestTemplate(); FileUploadResponse[] result;/*from www . j a v a2 s. com*/ try { final String url = getFileUploadUrl(httpServletRequest); final String fileName = files[0].getOriginalFilename(); final LinkedMultiValueMap<String, Object> body = new LinkedMultiValueMap<String, Object>(); final ByteArrayResource contentsAsResource = new ByteArrayResource(files[0].getBytes()) { @Override public String getFilename() { return fileName; } }; body.add("files", contentsAsResource); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); headers.add("Authorization", "Basic " + Base64.encodeBase64String(new StringBuilder(securityService.getUserName()) .append(":").append(getHash()).toString().getBytes())); final HttpEntity<LinkedMultiValueMap<String, Object>> request = new HttpEntity<LinkedMultiValueMap<String, Object>>( body, headers); result = restTemplate.postForObject(url, request, FileUploadResponse[].class); } catch (Exception e) { throw new RuntimeException(e); } LOGGER.debug("end of uploadFile method" + result); return result; }
From source file:fr.itldev.koya.services.impl.KoyaContentServiceImpl.java
private Document upload(User user, NodeRef parent, Object o) throws AlfrescoServiceException { MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>(); parts.add("filedata", o); parts.add("destination", parent.toString()); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(parts, headers); AlfrescoUploadReturn upReturn = fromJSON(new TypeReference<AlfrescoUploadReturn>() { }, user.getRestTemplate().postForObject(getAlfrescoServerUrl() + REST_POST_UPLOAD, request, String.class)); return (Document) getSecuredItem(user, upReturn.getNodeRef()); }
From source file:com.weibo.api.Statuses.java
/** * http://open.weibo.com/wiki/2/statuses/upload * @param status/*from w w w . j a va 2s . co m*/ * @param visible * @param listId * @param pic * @param accessToken * @return */ public Status upload(String status, Visible visible, String listId, String pic, String accessToken) { MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>(); map.add("status", status); if (visible != null) { map.add("visible", visible.getCode()); if (visible == Visible.GROUP) { map.add("list_id", listId); } } map.add("pic", new ClassPathResource(pic)); map.add("access_token", accessToken); return weiboHttpClient.post(STATUSES_UPLOAD_URL, map, Status.class, MediaType.MULTIPART_FORM_DATA); }
From source file:com.httpMessageConvert.FormHttpMessageConverter.java
public FormHttpMessageConverter() { System.out.println("convert"); this.supportedMediaTypes.add(MediaType.APPLICATION_FORM_URLENCODED); this.supportedMediaTypes.add(MediaType.MULTIPART_FORM_DATA); this.partConverters.add(new ByteArrayHttpMessageConverter()); StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter(); stringHttpMessageConverter.setWriteAcceptCharset(false); this.partConverters.add(stringHttpMessageConverter); this.partConverters.add(new ResourceHttpMessageConverter()); }
From source file:com.aestheticsw.jobkeywords.service.termextractor.impl.fivefilters.FiveFiltersClient.java
public String[][] executeFiveFiltersPost(String content) { String query = "http://termextract.fivefilters.org/extract.php"; MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(); params.add("text", content); params.add("output", "json"); params.add("max", "300"); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setContentType(MediaType.MULTIPART_FORM_DATA); HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>( params, requestHeaders);// ww w .ja v a2 s . c om ResponseEntity<String[][]> stringArrayEntty = restTemplate.exchange(query, HttpMethod.POST, requestEntity, String[][].class); String[][] stringArray = stringArrayEntty.getBody(); return stringArray; }