Using Dropbox API to upload a file with Android

前端 未结 5 512
庸人自扰
庸人自扰 2020-12-08 15:31

How can I upload a File (graphic, audio and video file) with Android using the Dropbox API to Dropbox? I followed the tutorial on the Dropbox SDK Android page and could get

5条回答
  •  感动是毒
    2020-12-08 16:23

    Here is another example which uses the Dropbox v2 API but a 3rd party SDK. It works exactly the same for Google Drive, OneDrive and Box.com by the way.

    // CloudStorage cs = new Box(context, "[clientIdentifier]", "[clientSecret]");
    // CloudStorage cs = new OneDrive(context, "[clientIdentifier]", "[clientSecret]");
    // CloudStorage cs = new GoogleDrive(context, "[clientIdentifier]", "[clientSecret]");
    CloudStorage cs = new Dropbox(context, "[clientIdentifier]", "[clientSecret]");
    new Thread() {
        @Override
        public void run() {
            cs.createFolder("/TestFolder"); // <---
            InputStream stream = null;
            try {
                AssetManager assetManager = getAssets();
                stream = assetManager.open("UserData.csv");
                long size = assetManager.openFd("UserData.csv").getLength();
                cs.upload("/TestFolder/Data.csv", stream, size, false); // <---
            } catch (Exception e) {
                // TODO: handle error
            } finally {
                // TODO: close stream
            }
        }
    }.start();
    

    It uses the CloudRail Android SDK

提交回复
热议问题