0

I'm trying to upload a NEW .txt file to my Dropbox folder from my android app. Whatever I do it keeps saying that the file or directory doesn't exist. What am I doing wrong here?

When the user clicks a button in my view I would like to create a new file into my Dropbox folder. The dropbox folder its path is Dropbox\Apps\myApp In the directory myApp I would like to add a new txt file with for example the text "this is my new file." in it.

 public  void fileButtonClick(View v){
        FileInputStream inputStream = null;
         try {
             File file = new File("/Apps/Finance+");
             inputStream = new FileInputStream(file);
             Entry newEntry = mDBApi.putFile("/file.txt", inputStream,
                     file.length(), null, null);
         } catch (Exception e) {
             System.out.println("Something went wrong: " + e);
         } finally {
             if (inputStream != null) {
                 try {
                     inputStream.close();
                 } catch (IOException e) {}
             }
         }
    }

Can anybody tell me what I am doing wrong and how I can find the correct path / option to make a new file?

Thanks Yenthe

Yenthe
  • 2,313
  • 5
  • 26
  • 46
  • How do you create mDBApi? Are you using Sandbox or Dropbox folder as the root? – vijayst Oct 28 '13 at 08:23
  • Like this private DropboxAPI mDBApi; – Yenthe Oct 28 '13 at 10:54
  • If you're using an app folder app, you don't need to specify /Apps/{appfoldername} manually. Just using "/" will be the root of your app folder automatically. Also, it sounds like your code isn't working, but you haven't posted the error you're getting. Doing so would help us identify the problem. Finally I recommend working through the tutorial in full if you haven't already done so: https://www.dropbox.com/developers/core/start/android – Greg Oct 28 '13 at 20:18
  • Okay I changed the folder as you said with /. Also, I did follow the whole tutorial but I can't seem to get things up and running sadly.. This is a printscreen of my function and the error (which is amazingly small.) http://imgur.com/IivgJOV Thanks for your responses & help! Edit :the error also says open failed, which is normal because the file doesn't exist yet but I don't know how to say that he should make the file.. – Yenthe Oct 29 '13 at 10:06
  • @Greg, do you have any idea whats wrong? I'm still stuck at it :s – Yenthe Oct 31 '13 at 11:56
  • My comment was only directed at the remote path supplied to the Dropbox API. It looks like you've fixed that, but the current issue is likely referring to you trying to open a local file that doesn't exist. (new File("/Apps/Finance+");) Make sure you supply a path to a local file that exists. – Greg Oct 31 '13 at 14:34
  • Thats the thing.. the file doesn't exist and I want to create a NEW file :s @Greg – Yenthe Oct 31 '13 at 16:46
  • Something like this might help then: http://stackoverflow.com/questions/2885173/java-how-to-create-and-write-to-a-file – Greg Oct 31 '13 at 17:18

1 Answers1

0

I think the problem is that you are trying to sync a file that does not exist. putFile is used for files that have been created already. Try to first create some mockup file and then try your code and it should work, put the next code in say onCreate:

filename="testfile"
writer = new FileWriter(filename);
               writer.append("This is some random text I write to test this application");
                writer.flush();
                writer.close();

Then you can try:

File file = new File(filename);
                FileInputStream inputStream = null;
                try {
                    inputStream = new FileInputStream(file);
                    DropboxAPI.Entry response = null;
                    try {
                         response = mDBApi.putFile("/someother-file.txt", inputStream,
                            file.length(), null, null);
                } catch (DropboxException e) {
                    e.printStackTrace();
                }
                Log.i("DbExampleLog", "The uploaded file's rev is: " + response.rev);


            } catch (FileNotFoundException e) {
                e.printStackTrace();
ZygD
  • 22,092
  • 39
  • 79
  • 102
Juli
  • 1,011
  • 8
  • 16