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

Upload File Problem.. Result is 0 bytes

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




}

}
}

  • travis h.4's avatar
    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());

About Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,875 PostsLatest Activity: 2 hours 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!