cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Musicians, convert your MuseScore files to PDF to play music on the go! Learn more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: Java dropbox GUI

Java dropbox GUI

travis h.4
New member | Level 1

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();

}

}

 

 

 

4 Replies 4

Greg-DB
Dropbox 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
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_...

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
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){
}

Greg-DB
Dropbox Staff

Note, for anyone following along who may be having the same problem, another one of our developer advocates offered an answer on the StackOverflow question.

Need more support?