简体   繁体   English

android dropbox api文件上传

[英]android dropbox api file upload

I am implementing dropbox integration in my android app.I have done file uploading ie my file is uploaded successfully on dropbox but how can i check if a same file exists on dropbox and create a new copy of the file on dropbox.Please help me 我正在Android应用程序中实现Dropbox集成。我已经完成了文件上传,即我的文件已成功上传到Dropbox上,但如何检查Dropbox上是否存在相同文件并在Dropbox上创建文件的新副本。请帮助我

my code for upload is below: 我的上传代码如下:

    FileInputStream fis = new FileInputStream(alUploadFile.get(i));

            String path = mPath+"/"+ alUploadFile.get(i).getName();

            mRequest = mApi.putFileOverwriteRequest(path, fis,
                    alUploadFile.get(i).length(), new ProgressListener() {
                        @Override
                        public long progressInterval() {
                            // Update the progress bar every half-second or
                            // so
                            return 1;
                        }

                        @Override
                        public void onProgress(long bytes, long total) {
                            publishProgress(bytes);
                        }
                    });

            if (mRequest != null) {
                mRequest.upload();
//              return true;
            }

If you want to check the result of the upload, you can look at the DropboxAPI.Entry returned by the DropboxAPI.UploadRequest.upload method. 如果您想检查上传的结果,你可以看看DropboxAPI.Entry用返回DropboxAPI.UploadRequest.upload方法。 Eg, the Entry 's path will give you the location of the uploaded file. 例如, Entrypath将为您提供上载文件的位置。

If you want to check the state of the account at any point in time, when not doing an upload, you can use DropboxAPI.metadata or DropboxAPI.delta . 如果要在任何时间检查帐户状态,则在不进行上传时,可以使用DropboxAPI.metadataDropboxAPI.delta

private boolean exists(String path) {
    try {
         Entry existingEntry = mApi.metadata(path, 1, null, false, null);
         return true;
     } catch (DropboxServerException e) {
        if(e.error == DropboxServerException._404_NOT_FOUND)
            return false;
        throw e;
     }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM