@@ -0,0 +1,2489 @@
+package dropbox;%0A%0Aimport com.dropbox.core.DbxRequestConfig;%0Aimport com.dropbox.core.v2.DbxClientV2;%0Aimport com.dropbox.core.v2.files.FileMetadata;%0Aimport com.sendgrid.Attachments;%0Aimport org.apache.commons.codec.binary.Base64;%0A%0Aimport java.io.ByteArrayInputStream;%0Aimport java.io.InputStream;%0Aimport java.nio.charset.Charset;%0A/*%0A    Add Dropbox dependencies for compiling code%0A    Gradle : compile 'com.dropbox.core:dropbox-core-sdk:3.0.5'%0A    maven :%0A    %3Cdependency%3E%0A       %3CgroupId%3Ecom.dropbox.core%3C/groupId%3E%0A       %3CartifactId%3Edropbox-core-sdk%3C/artifactId%3E%0A       %3Cversion%3E3.0.5%3C/version%3E%0A    %3C/dependency%3E%0A */%0Apublic class UploadToDropBox %7B%0A    public static void main(String%5B%5D args) %7B%0A        String fileName = %22book3.txt%22;%0A        String type = %22text/plain%22;%0A        String content = %22This test checks if the builder works fine%22;%0A        InputStream contentStream = new ByteArrayInputStream(content.getBytes(Charset.forName(%22UTF-8%22)));%0A        String contentId = %22someId%22;%0A        String dispositon = %22someDisposition%22;%0A        String accessToken = %22user's access token%22;%0A        String path = %22/path/to/folder%22;%0A%0A        Attachments attachments = new Attachments.Builder(fileName, contentStream)%0A                .withType(type)%0A                .withContentId(contentId)%0A                .withDisposition(dispositon)%0A                .build();%0A        String returnPath = uploadToDropbox(attachments, accessToken, path);%0A        System.out.println(%22Path: %22 + returnPath);%0A    %7D%0A%0A    /**%0A     * Uploads attachment to Dropbox%0A     *%0A     * @param attachments attachment to be uploaded%0A     * @param accessToken user's Dropbox access token%0A     * @param path path of the folder in which attachment needs to be added. Should not end with /%0A     * @return the full path to the uploaded file%0A     */%0A    private static String uploadToDropbox(Attachments attachments, String accessToken, String path)%7B%0A        try %7B%0A            DbxRequestConfig config = DbxRequestConfig.newBuilder(%22sendgrid/0.1%22).build();%0A            DbxClientV2 client = new DbxClientV2(config, accessToken);%0A            FileMetadata uploadedFile = client.files().upload(String.format(%22%25s/%25s%22, path, attachments.getFilename()))%0A                    .uploadAndFinish(new ByteArrayInputStream((Base64.decodeBase64(attachments.getContent()))));%0A            return uploadedFile.getPathDisplay();%0A        %7Dcatch(Exception ex) %7B%0A            throw new RuntimeException(%22Error while uploading to Dropbox%22, ex);%0A        %7D%0A    %7D%0A%0A%7D%0A%0A

Save attachment to Dropbox (#304)