We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
lalit j.
11 years agoNew member | Level 1
Check File exist before uploading DropBoxApi
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();
}
}
1 Reply
Replies have been turned off for this discussion
- Greg-DB11 years ago
Dropbox Community Moderator
[Cross-linking for reference: https://stackoverflow.com/questions/31314298/dropboxapi-check-file-exist-or-not and https://stackoverflow.com/questions/31324098/check-file-exist-before-uploading-dropboxapi ]
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
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, Facebook or Instagram.
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!