i using following code check file exist in dropbox before uploading avoid duplication.i using following line check returning false postexceute means "failed 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 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 upload file", toast.length_long) .show(); } }
Comments
Post a Comment