Box java sdk - download converted file
回答済み
Here is the flow I am trying to achieve. I am using BOX Java SDK in my application to invoke BOX API.
- A bunch of files get uploaded to a folder (monitored by webhook)
- Application receives webhook trigger for each FILE (metadata )
- If FILE is a non-PDF (RTF, XLS) then convert to PDF
- Upload the converted file to BOX to a different folder
My draft implementation is centered around downloading file to local server on which application is running and then use itext/POI to convert non-PDF to PDF and upload PDF version to BOX.
Is there a simpler approach or a solution this ?
-
Hey ,
Apologies for the late reply! The good new is that there is a convenient way to achieve this via the Box API without downloading to local server and converting and re-uploading.
Once a file is uploaded to Box you can fetch different representations of the file you uploaded. You can absolutely retrieve a PDF representation of the file you uploaded. The flow would go roughly as follows:
- Upload your file to Box
- Make a call to the /representations endpoint with the pdf file type in the x-reps-hint header field.
- Get back the pdf representation of your file uploaded.
For step by step on how to do this please refer to our API Reference for Get Representations
This functionality is also implemented in the Box Java SDK. For code example please refer to docs here.
Please note that this is a two part process. Sometimes representations are not available immediately after a file is uploaded. If you are running your script at a later time after you upload then this should not be a problem. However, if you are running your script directly after uploading then you will need to call the `getInfoWithRepresentations(...)` method and check the status for pdf representation, then call `getRepresentationContent(...)` to return an output stream of your pdf file.
If you have any issues please do not hesitate to reach out!
-
Hey, is there representation related feature also in box-android-sdk ?
I have been looking for some example like this:
https://github.com/box/box-java-sdk/blob/master/doc/files.md#get-file-representations
But for android one:
https://github.com/box/box-android-sdk/blob/master/doc/Files.md
I tried to compose getting representations by myself, but representations are always null. So I am looking for some proven sample.
My current approach is to get com.box.androidsdk.content.models.Boxfile and check it's representations -> this is unfortunatelly always null. If there would be required representation, I would pass it as parameter to another call com.box.androidsdk.content.BoxApiFile.getDownloadRepresentationRequest and hopefully get proper file in required representation.
Could you point me to some working sample? Or have you any idea, how to get proper representation object for file saved in box?
サインインしてコメントを残してください。
コメント
3件のコメント