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();
}
}
existingentry. What do you get if you log it out? Are you getting any output or errors you can add to the question?new File("file").exists()