Search in sources :

Example 1 with FileUploadParams

use of com.box.sdk.FileUploadParams in project camel by apache.

the class BoxFilesManager method uploadFile.

/**
     * Upload a new file to parent folder.
     * 
     * @param parentFolderId
     *            - the id of parent folder.
     * @param content
     *            - a stream containing contents of the file to upload.
     * @param fileName
     *            the name to give the uploaded file.
     * @param created
     *            - the content created date that will be given to the uploaded
     *            file.
     * @param modified
     *            - the content modified date that will be given to the uploaded
     *            file.
     * @param size
     *            - the size of the file's content used for monitoring the
     *            upload's progress.
     * @param listener
     *            - a listener for monitoring the upload's progress.
     * @return The uploaded file.
     */
public BoxFile uploadFile(String parentFolderId, InputStream content, String fileName, Date created, Date modified, Long size, ProgressListener listener) {
    try {
        LOG.debug("Uploading file with name '" + fileName + "' to parent_folder(id=" + parentFolderId + ")");
        if (parentFolderId == null) {
            throw new IllegalArgumentException("Parameter 'parentFolderId' can not be null");
        }
        if (content == null) {
            throw new IllegalArgumentException("Paramerer 'content' can not be null");
        }
        if (fileName == null) {
            throw new IllegalArgumentException("Paramerer 'fileName' can not be null");
        }
        BoxFolder parentFolder = new BoxFolder(boxConnection, parentFolderId);
        FileUploadParams uploadParams = new FileUploadParams();
        uploadParams.setName(fileName);
        uploadParams.setContent(content);
        if (created != null) {
            uploadParams.setCreated(created);
        }
        if (modified != null) {
            uploadParams.setModified(modified);
        }
        if (size != null) {
            uploadParams.setSize(size);
        }
        if (listener != null) {
            uploadParams.setProgressListener(listener);
        }
        return parentFolder.uploadFile(uploadParams).getResource();
    } catch (BoxAPIException e) {
        throw new RuntimeException(String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e);
    }
}
Also used : FileUploadParams(com.box.sdk.FileUploadParams) BoxAPIException(com.box.sdk.BoxAPIException) BoxFolder(com.box.sdk.BoxFolder)

Aggregations

BoxAPIException (com.box.sdk.BoxAPIException)1 BoxFolder (com.box.sdk.BoxFolder)1 FileUploadParams (com.box.sdk.FileUploadParams)1