Skip to content

Fix error on InputStream conversion #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
Config.setDefaultApiCredentials(getenv("API_TOKEN")); // Get your api token at https://www.convertapi.com/a/authentication

// Creating file data stream
InputStream stream = Files.newInputStream(new File("src/main/resources/test.docx").toPath());

System.out.println("Converting stream of DOCX data to PDF");
CompletableFuture<ConversionResult> result = ConvertApi.convert("docx", "pdf",
try (InputStream stream = Files.newInputStream(new File("src/main/resources/test.docx").toPath())) {
System.out.println("Converting stream of DOCX data to PDF");
CompletableFuture<ConversionResult> result = ConvertApi.convert("docx", "pdf",
new Param("file", stream, "test.docx")
);
);

Path pdfFile = Paths.get(System.getProperty("java.io.tmpdir") + "/myfile.pdf");
result.get().saveFile(pdfFile).get();
Path pdfFile = Paths.get(System.getProperty("java.io.tmpdir") + "/myfile.pdf");
result.get().saveFile(pdfFile).get();

System.out.println("PDF file saved to: " + pdfFile.toString());
System.out.println("PDF file saved to: " + pdfFile.toString());
}
}
}
9 changes: 0 additions & 9 deletions src/main/java/com/convertapi/client/RequestBodyStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ public MediaType contentType() {
return mediaType;
}

@Override
public long contentLength() {
try {
return inputStream.available();
} catch (IOException e) {
return 0;
}
}

@Override
public void writeTo(BufferedSink sink) throws IOException {
Source source = null;
Expand Down