Search in sources :

Example 1 with BoxEntity

use of com.box.androidsdk.content.models.BoxEntity in project box-android-sdk by box.

the class MainActivity method uploadSampleFile.

/**
     * Method demonstrates a sample file being uploaded using the file api
     */
private void uploadSampleFile() {
    mDialog = ProgressDialog.show(MainActivity.this, getText(R.string.boxsdk_Please_wait), getText(R.string.boxsdk_Please_wait));
    new Thread() {

        @Override
        public void run() {
            try {
                String uploadFileName = "box_logo.png";
                InputStream uploadStream = getResources().getAssets().open(uploadFileName);
                String destinationFolderId = "0";
                String uploadName = "BoxSDKUpload.png";
                BoxRequestsFile.UploadFile request = mFileApi.getUploadRequest(uploadStream, uploadName, destinationFolderId);
                final BoxFile uploadFileInfo = request.send();
                showToast("Uploaded " + uploadFileInfo.getName());
                loadRootFolder();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (BoxException e) {
                e.printStackTrace();
                BoxError error = e.getAsBoxError();
                if (error != null && error.getStatus() == HttpStatus.SC_CONFLICT) {
                    ArrayList<BoxEntity> conflicts = error.getContextInfo().getConflicts();
                    if (conflicts != null && conflicts.size() == 1 && conflicts.get(0) instanceof BoxFile) {
                        uploadNewVersion((BoxFile) conflicts.get(0));
                        return;
                    }
                }
                showToast("Upload failed");
            } finally {
                mDialog.dismiss();
            }
        }
    }.start();
}
Also used : BoxException(com.box.androidsdk.content.BoxException) BoxError(com.box.androidsdk.content.models.BoxError) InputStream(java.io.InputStream) BoxFile(com.box.androidsdk.content.models.BoxFile) IOException(java.io.IOException) BoxEntity(com.box.androidsdk.content.models.BoxEntity)

Example 2 with BoxEntity

use of com.box.androidsdk.content.models.BoxEntity in project box-android-sdk by box.

the class BoxRequestCommentAdd method setItemId.

/**
     * Sets the id of the item used in the request to add a comment to.
     *
     * @param id    id of the item to add a comment to.
     * @return  request with the updated item id.
     */
protected R setItemId(String id) {
    JsonObject object = new JsonObject();
    if (mBodyMap.containsKey(BoxComment.FIELD_ITEM)) {
        BoxEntity item = (BoxEntity) mBodyMap.get(BoxComment.FIELD_ITEM);
        object = item.toJsonObject();
    }
    object.add(BoxEntity.FIELD_ID, id);
    BoxEntity item = new BoxEntity(object);
    mBodyMap.put(BoxComment.FIELD_ITEM, item);
    return (R) this;
}
Also used : JsonObject(com.eclipsesource.json.JsonObject) BoxEntity(com.box.androidsdk.content.models.BoxEntity)

Example 3 with BoxEntity

use of com.box.androidsdk.content.models.BoxEntity in project box-android-sdk by box.

the class BoxRequestCommentAdd method setItemType.

/**
     * Sets the type of item used in the request to add a comment to.
     *
     * @param type  type of item used in the request. Must be "file", "comment", or "web_link".
     * @return  request with the updated item type.
     */
protected R setItemType(String type) {
    JsonObject object = new JsonObject();
    if (mBodyMap.containsKey(BoxComment.FIELD_ITEM)) {
        BoxEntity item = (BoxEntity) mBodyMap.get(BoxComment.FIELD_ITEM);
        object = item.toJsonObject();
    }
    object.add(BoxEntity.FIELD_TYPE, type);
    BoxEntity item = new BoxEntity(object);
    mBodyMap.put(BoxComment.FIELD_ITEM, item);
    return (R) this;
}
Also used : JsonObject(com.eclipsesource.json.JsonObject) BoxEntity(com.box.androidsdk.content.models.BoxEntity)

Aggregations

BoxEntity (com.box.androidsdk.content.models.BoxEntity)3 JsonObject (com.eclipsesource.json.JsonObject)2 BoxException (com.box.androidsdk.content.BoxException)1 BoxError (com.box.androidsdk.content.models.BoxError)1 BoxFile (com.box.androidsdk.content.models.BoxFile)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1