private HttpResponse putRequest( byte[] bytes, int position, int length, String fileType, HttpRequestFactory requestFactory, long size, String location) throws HttpResponseException { try { InputStreamContent inputStreamContent = new InputStreamContent(fileType, new ByteArrayInputStream(bytes)); HttpRequest chunkRequest = requestFactory.buildPutRequest(new DocsUrl(location), inputStreamContent); chunkRequest.getHeaders().setContentRange(range(position, length, size)); chunkRequest.getHeaders().setContentLength((long) length); return requestExecutor.executeNonSensitive(chunkRequest); } catch (HttpResponseException e) { throw e; } catch (Exception e) { String message = "unable to upload chunk number " + position + ", " + e.getMessage(); logger.error(message); throw new CoreException(message, e); } }
private String initUpload( HttpRequestFactory requestFactory, DocsUrl url, long size, String fileType, AtomContent fileContent) throws IOException { HttpRequest request = requestFactory.buildPostRequest(url, fileContent); request.getHeaders().set("X-Upload-Content-Type", fileType); request.getHeaders().set("X-Upload-Content-Length", size); HttpResponse response = requestExecutor.executeNonSensitive(request); if (!response.isSuccessStatusCode()) { throw new CoreException( "unable to initiate upload, " + response.getStatusCode() + ": " + response.getStatusMessage()); } response.ignore(); return response.getHeaders().getLocation(); }