We're making changes to the Community, so you may have received some notifications - thanks for your patience and welcome back. Learn more here.

Forum Discussion

travis h.4's avatar
travis h.4
New member | Level 1
9 years ago

Java dropbox GUI

How would one go about creating a uploadFile method in Java that has a GUI? for example I am trying to use JFileChooser to execute a selected file in which I can click on the file and call the file and pass it into a file then send it out as a fileInputStream so looking at the code cause its a lot easier to explain. 

 

Something like this..

 

JFileChooser fc = new JFileChooser();

fc.getSelectedFile();

File inputFile = fc.getSelectedFile();
FileInputStream inputStream = new FileInputStream(inputFile);

try {



DbxEntry.File uploadedFile = client.uploadFile("/javaroots.jpg",

DbxWriteMode.add(), inputFile.length(), inputStream);

String sharedUrl = client.createShareableUrl("/javaroots.jpg");

System.out.println("Uploaded: " + uploadedFile.toString() + " URL " + sharedUrl);

} finally {

inputStream.close();

}

}

 

 

 

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    Where are you stuck exactly? Are you having trouble with the Dropbox portion of this? If so, what error are you getting?

    The matter of building a GUI around it is out of scope for Dropbox API support so I'm afraid this wouldn't be a good place for help with that aspect of your project.

  • travis h.4's avatar
    travis h.4
    New member | Level 1

    Thanks for the response Gregory,

     

    Yes, I am having troubles in context of the actual file upload method. The main guts of the program; user logging into dropbox and getting a access link etc. is working and connecting fine with no problems but when the upload method is executed I am getting errors (posted below this reply) the File object ( File file = getSelectedFile(); or File file = new File(); ) is all in red underline? 

    I also have a question posted in StackoverFlow pertaining to this question if you would like to look perhaps http://stackoverflow.com/questions/34505240/file-fileinputstream-issue?noredirect=1#comment56752945_34505240

    If you would like any more info. in context of this I can post the whole program as well if need to be. I appreciate your response, Happy New Year!

     

     

     

     

     

     

    OUTPUT:

    Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - no suitable constructor found for File(java.lang.String) constructor com.dropbox.core.DbxEntry.File.File(java.lang.String,java.lang.String,boolean,long,java.lang.String,java.util.Date,java.util.Date,java.lang.String,com.dropbox.core.DbxEntry.File.PhotoInfo,com.dropbox.core.DbxEntry.File.VideoInfo) is not applicable (actual and formal argument lists differ in length) constructor com.dropbox.core.DbxEntry.File.File(java.lang.String,java.lang.String,boolean,long,java.lang.String,java.util.Date,java.util.Date,java.lang.String) is not applicable (actual and formal argument lists differ in length) at daword.dropBox.actionPerformed(dropBox.java:173) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) at

  • travis h.4's avatar
    travis h.4
    New member | Level 1

    I should highlight also that I'm not trying to focus on the GUI question I am having success with that portion its just simply this bit of code hanging me up...

     

     

    public void uploadFile() throws FileNotFoundException, DbxException, IOException{

    fc = new JFileChooser();
    fc.setMultiSelectionEnabled(true);
    //fc.setFileSelectionMode();

    int dialog = fc.showSaveDialog(this);

    if (dialog == JFileChooser.APPROVE_OPTION) {

    inputFile = fc.getSelectedFile();
    inputFile.getAbsoluteFile();


    try{
    FileInputStream inputStream = new FileInputStream(inputFile);
    // this is where its not uploading all the code above is running fine

    uploadedFile = client.uploadFile(homeDir,
    DbxWriteMode.add(), inputFile.length(), inputStream);
    String sharedUrl = client.createShareableUrl(homeDir);
    System.out.println("Uploaded: " + uploadedFile.toString() + " URL " + sharedUrl);
    } catch (IOException e){
    }

About Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,875 PostsLatest Activity: 33 minutes ago
323 Following

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 or Facebook.

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!