SmartlingClient { public ContextUpload uploadContext(String projectId, String name, byte[] content) { ByteArrayResource contentAsResource = new NamedByteArrayResource(content, name); MultiValueMap<String, Object> body = new LinkedMultiValueMap<>(); body.add("content", contentAsResource); body.add("name", name); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers); try { ContextUploadResponse contextUploadResponse = oAuth2RestTemplate.postForObject(API_CONTEXTS, requestEntity, ContextUploadResponse.class, projectId); throwExceptionOnError(contextUploadResponse, ERROR_CANT_UPLOAD_CONTEXT, name); return contextUploadResponse.getData(); } catch(HttpClientErrorException e) { throw wrapIntoSmartlingException(e, ERROR_CANT_UPLOAD_CONTEXT, name); } } SmartlingClient(OAuth2RestTemplate oAuth2RestTemplate); Stream<StringInfo> getStringInfos(String projectId, String fileUri); Items<File> getFiles(String projectId); String downloadFile(String projectId, String locale, String fileUri, boolean includeOriginalStrings, RetrievalType retrievalType); String downloadPublishedFile(String projectId, String locale, String fileUri, boolean includeOriginalStrings); void deleteFile(String projectId, String fileUri); FileUploadResponse uploadFile(String projectId, String fileUri, String fileType, String fileContent, String placeholderFormat, String placeholderFormatCustom); FileUploadResponse uploadLocalizedFile(String projectId,
                                                  String fileUri,
                                                  String fileType,
                                                  String localeId,
                                                  String fileContent,
                                                  String placeholderFormat,
                                                  String placeholderFormatCustom); Items<StringInfo> getSourceStrings(String projectId, String fileUri, Integer offset, Integer limit); ContextUpload uploadContext(String projectId, String name, byte[] content); void createBindings(Bindings bindings, String projectId);  }
@Test public void testUploadContext() throws IOException { Assume.assumeNotNull(smartlingTestConfig.projectId); ClassPathResource classPathResource = new ClassPathResource("/com/box/l10n/mojito/img/1.png"); byte[] content = ByteStreams.toByteArray(classPathResource.getInputStream()); smartlingClient.uploadContext(smartlingTestConfig.projectId, "image1.png", content); }
@Test public void testUploadContextPNGUpperCase() throws IOException { Assume.assumeNotNull(smartlingTestConfig.projectId); ClassPathResource classPathResource = new ClassPathResource("/com/box/l10n/mojito/img/1.png"); byte[] content = ByteStreams.toByteArray(classPathResource.getInputStream()); smartlingClient.uploadContext(smartlingTestConfig.projectId, "caseissuewithpng.PNG", content); }