在上传DropBoxApi之前检查文件是否存在

时间:2015-07-09 17:12:26

标签: android dropbox

我在上传之前使用以下代码检查文件是否存在于dropbox中以避免重复。我正在使用以下行检查但是它返回false到PostExceute意味着"无法上传文件"。

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

实际方法:

 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();
        }
    }

0 个答案:

没有答案
相关问题