RestFB any idea how can i know the uploading progress of the video?

99 views Asked by At

I want to post a video with Rest FB

try {
        FileInputStream fis = new FileInputStream(new File("MySuperFile"));
        FacebookType response = facebookClient.publish(user.getId()+"/videos", FacebookType.class,
                                                BinaryAttachment.with("formatOfMySuperVideo",fis),
                                                Parameter.with("description","TheDescriptionOfMySuperVideo"));
} catch (FileNotFoundException ea) {}

it works very well BUT i would like to know if it's possible to know the "status" of the uploading. I mean i would like to have a progress bar or the percentage or something like that.

Thanks a lot !

2

There are 2 answers

6
Xephi On

Your publish method will return an instance of a Video i think, where you can find the source code here : Video.java

Also check response is the correct type :

if (response instanceof Video)
    // Do Something

You can now get the video status : Video.java#L644

Video video = (Video) response;
response.getStatus().getProcessingProgress(); // Contain a percentage

Edit : It look you have to change your code a bit to get a Video :

try {
    FileInputStream fis = new FileInputStream(new File("MySuperFile"));
    Video response = facebookClient.publish(user.getId()+"/videos", Video.class, BinaryAttachment.with("formatOfMySuperVideo",fis), Parameter.with("description","TheDescriptionOfMySuperVideo"));
    response.getStatus().getProcessingProgress(); // Contain the upload percentage
} catch (FileNotFoundException ea) {}
0
Uriel Díaz On

First all you need to do another request in order to get the video fields. I mean after you did publish request you should get a postId, in that way the next step to do is:

Video video  facebookClient.fetchObject(response.getId(),Video.class, Parameter.with("fields", "status"));

And maybe test with a debug:

logger.debug("Progress... " + video.getStatus().getProcessingProgress());