We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
Aurelian R.
11 years agoNew member | Level 1
Download a file from the Dropbox account into an output stream.
Hello
I download a file from Dropbox using the following code from the Dropbox API:
public final OutputStream downloadDropBoxFileAtOutputStream(final String dropBoxFilePath, String localFilePath) {
OutputStream outputStream = null;
try {
outputStream = new FileOutputStream(localFilePath);
} catch (FileNotFoundException e) {
LOGGER.error(e.getMessage());
}
try {
DbxEntry.File downloadedFile = null;
try {
downloadedFile = client.getFile(dropBoxFilePath, null,
outputStream);
} catch (DbxException | IOException e) {
LOGGER.error(e.getMessage());
}
} finally {
try {
outputStream.close();
} catch (IOException e) {
LOGGER.error(e.getMessage());
}
}
return outputStream;
}
I want to pass the resulted output stream to another method without saving the file on the local disk. Is is this possible with the Dropbox core java API ?
Best Regards,
Aurelian
1 Reply
Replies have been turned off for this discussion
- Greg-DB11 years ago
Dropbox Community Moderator
The
getFilemethod will just write the file contents to whateverOutputStreamyou supply, which doesn't necessarily need to be aFileOutputStreamlike the example in the documentation shows. That being the case, you supply a different kind ofOutputStreamto send the data to wherever you want. For example, aPipedOutputStreammay make sense, depending on your scenario.Alternatively, you may want to use
startGetFilewhich returns aDbxClient.Downloaderinstead, which has anInputStreamwith the file's contents as thebodyfield, which may suit your use case better.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!