0

I am using following code to check file exist in dropbox before uploading to avoid duplication.I am using following line to check but it is returning false to PostExceute means "Failed to upload file".

Entry existingentry= dropbox.metadata(path + "sample.txt",1,null,false,null);

Actual Method:

 protected Boolean doInBackground(Void... params) {
        final File tempDir = context.getCacheDir();
        File tempFile;
        FileWriter fr;
        try {
            tempFile = File.createTempFile("file", ".txt", tempDir);
            fr = new FileWriter(tempFile);
            fr.write("Test file uploaded using Dropbox API for Android");
            fr.close();

            FileInputStream fileInputStream = new FileInputStream(tempFile);

          Entry existingentry= dropbox.metadata(path + "sample.txt",1,null,false,null);

                dropbox.putFile(path + "sample.txt", fileInputStream,
                        tempFile.length(), null, null);
                tempFile.delete();

            return true;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (DropboxException e) {
            e.printStackTrace();
        }
        return false;
    }


 @Override
    protected void onPostExecute(Boolean result) {
        if (result) {
            Toast.makeText(context, "File Uploaded Successfully!",
                    Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(context, "Failed to upload file", Toast.LENGTH_LONG)
                    .show();
        }
    }
4
  • [Cross-linking for reference: dropboxforum.com/hc/communities/public/questions/… ]
    – Greg
    Commented Jul 9, 2015 at 19:37
  • You don't seem to actually read existingentry. What do you get if you log it out? Are you getting any output or errors you can add to the question?
    – Greg
    Commented Jul 9, 2015 at 19:38
  • new File("file").exists() Commented Jul 9, 2015 at 20:23
  • I want to check file in dropbox account Commented Jul 10, 2015 at 4:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.