cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and 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: 

Upload File Problem.. Result is 0 bytes

Upload File Problem.. Result is 0 bytes

travis h.4
New member | Level 1

Hello,

 

Im having a parable uploading my files to dropbox Im using JAVA and the dropbox API my problem is everytime I try to upload the file I am going into dropbox on my browser and trying to look at the file but it appears to be 0 bytes? I don't know where its getting corrupted it doesn't make sense to me I've played around with it a bit and haven't had any luck... I have my code below

 

This is my upload method I have took off the exceptions as no-one really wants to read that mess

 

// Working Upload Method To DropBox Cloud

 


public void uploadFile ()  {

// autheticate if there is a accessToken here if not prompt to login by activating the drop method re-auth..
try{
phoneHome();
}catch(IOException e){
System.out.println("not saving accessToken");
JOptionPane.showMessageDialog(null, "Your Access Information Does Not Exist,\n Please Login"+
"Please Login By Clicking 'OK'");
drop(); // will run auth method for user to login
}

// user picks file to upload with JFileChooser
fc = new JFileChooser();
fc.setMultiSelectionEnabled(true);
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int dialog = fc.showSaveDialog(this);
if (dialog == JFileChooser.APPROVE_OPTION) {

inputFile = fc.getSelectedFile();
inputFile.getName();
inputFile.getAbsoluteFile();
inputFile.getAbsolutePath();
String nameOf = inputFile.getName();
System.out.println(" File: " + inputFile);


try{


setTitle("Uploading File..");
inputStream = new FileInputStream(inputFile);


// getting 0 bytes because no data is going through stream file corrupted

 


DbxEntry.File uploadedFile = client.uploadFile("/", DbxWriteMode.add(), inputFile.length(), inputStream);


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

JOptionPane.showMessageDialog(null,"File Upload:" + uploadedFile.toString(),
"Success!", JOptionPane.WARNING_MESSAGE);



 

}catch (IOException e){
e.printStackTrace();
JOptionPane.showMessageDialog(null,"Failed To Upload File",
"Attention", JOptionPane.WARNING_MESSAGE);
}finally{
inputStream.close();
setTitle("DropBox Integration");




}

}
}

1 Reply 1

travis h.4
New member | Level 1

SOLVED

 

 

File selectedFile = new File(nameOf+inputFile);
inputStream = new FileInputStream(inputFile);

 

 uploadedFile = client.uploadFile( "/" +selectedFile ,DbxWriteMode.add(), inputFile.length(), inputStream);


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

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    travis h.4 New member | Level 1
What do Dropbox user levels mean?