Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.box.androidsdk.content;
  
  import java.io.File;
  import java.util.Date;
 
Represents the API of the file endpoint on Box. This class can be used to generate request objects for each of the APIs exposed endpoints
 
 public class BoxApiFile extends BoxApi {

    
Constructs a BoxApiFile with the provided BoxSession

Parameters:
session authenticated session to use with the BoxApiFile
 
     public BoxApiFile(BoxSession session) {
         super(session);
     }

    
Gets the URL for files

Returns:
the file URL
 
     protected String getFilesUrl() { return String.format(."%s/files"getBaseUri()); }

    
Gets the URL for file information

Parameters:
id id of the file
Returns:
the file information URL
 
     protected String getFileInfoUrl(String id) { return String.format(."%s/%s"getFilesUrl(), id); }

    
Gets the URL for copying a file

Parameters:
id id of the file
Returns:
the copy file URL
 
     protected String getFileCopyUrl(String id) { return String.format(.getFileInfoUrl(id) + "/copy"); }

    
Gets the URL for uploading a file

Returns:
the file upload URL
 
     protected String getFileUploadUrl() { return String.format(."%s/files/content"getBaseUploadUri() ); }

    
Gets the URL for uploading a new version of a file

Parameters:
id id of the file
Returns:
the file version upload URL
 
     protected String getFileUploadNewVersionUrl(String id) { return String.format(."%s/files/%s/content"getBaseUploadUri(), id); }

    
Gets the URL for comments on a file

Parameters:
id id of the file
Returns:
the file comments URL
 
     protected String getTrashedFileUrl(String id) { return getFileInfoUrl(id) + "/trash"; }

    
Gets the URL for comments on a file

Parameters:
id id of the file
Returns:
the file comments URL
 
     protected String getFileCommentsUrl(String id) { return getFileInfoUrl(id) + "/comments"; }

    
Gets the URL for versions of a file

Parameters:
id id of the file
Returns:
the file versions URL
 
     protected String getFileVersionsUrl(String id) { return getFileInfoUrl(id) + "/versions"; }

    
Gets the URL for promoting the version of a file

Parameters:
id id of the file
Returns:
the file version promotion URL
 
     protected String getPromoteFileVersionUrl(String id) { return getFileVersionsUrl(id) + "/current"; }

    
Gets the URL for deleting the version of a file

Parameters:
id id of the file
Returns:
the file version deletion URL
    protected String getDeleteFileVersionUrl(String idString versionId) { return String.format(."%s/%s"getFileVersionsUrl(id), versionId); }

    
Gets the URL for downloading a file

Parameters:
id id of the file
Returns:
the file download URL
    protected String getFileDownloadUrl(String id) { return getFileInfoUrl(id) + "/content"; }

    
Gets the URL for downloading the thumbnail of a file

Parameters:
id id of the file
Returns:
the thumbnail file download URL
    protected String getThumbnailFileDownloadUrl(String id) { return getFileInfoUrl(id) + "/thumbnail.png"; }

    
Gets the URL for posting a comment on a file

Returns:
the comments URL
    protected String getCommentUrl() { return getBaseUri() + .; }


    
Gets a request that retrieves information on a file

Parameters:
id id of file to retrieve info on
Returns:
request to get a files information
    public BoxRequestsFile.GetFileInfo getInfoRequest(final String id) {
        BoxRequestsFile.GetFileInfo request = new BoxRequestsFile.GetFileInfo(idgetFileInfoUrl(id), );
        return request;
    }

    
Gets a request that updates a file's information

Parameters:
id id of file to update information on
Returns:
request to update a file's information
        BoxRequestsFile.UpdateFile request = new BoxRequestsFile.UpdateFile(idgetFileInfoUrl(id), );
        return request;
    }

    
Gets a request that copies a file

Parameters:
id id of the file to copy
parentId id of the parent folder to copy the file into
Returns:
request to copy a file
    public BoxRequestsFile.CopyFile getCopyRequest(String idString parentId) {
        BoxRequestsFile.CopyFile request = new BoxRequestsFile.CopyFile(idparentIdgetFileCopyUrl(id), );
        return request;
    }

    
Gets a request that renames a file

Parameters:
id id of file to rename
newName id of file to retrieve info on
Returns:
request to rename a file
    public BoxRequestsFile.UpdateFile getRenameRequest(String idString newName) {
        BoxRequestsFile.UpdateFile request = new BoxRequestsFile.UpdateFile(idgetFileInfoUrl(id), );
        request.setName(newName);
        return request;
    }

    
Gets a request that moves a file to another folder

Parameters:
id id of file to move
parentId id of parent folder to move file into
Returns:
request to move a file
    public BoxRequestsFile.UpdateFile getMoveRequest(String idString parentId) {
        BoxRequestsFile.UpdateFile request = new BoxRequestsFile.UpdateFile(idgetFileInfoUrl(id), );
        request.setParentId(parentId);
        return request;
    }

    
Gets a request that deletes a folder

Parameters:
id id of folder to delete
Returns:
request to delete a folder
        BoxRequestsFile.DeleteFile request = new BoxRequestsFile.DeleteFile(idgetFileInfoUrl(id), );
        return request;
    }

    
Gets a request that creates a shared link for a file

Parameters:
id id of file to create shared link for
Returns:
request to create a shared link for a file
                .setAccess(null);
        return request;
    }

    
Gets a request that disables a shared link for a folder

Parameters:
id id of folder to disable a shared link for
Returns:
request to create a shared link for a folder
        BoxRequestsFile.UpdateFile request = new BoxRequestsFile.UpdateFile(idgetFileInfoUrl(id), )
                .setSharedLink(null);
        return request;
    }

    
Gets a request that adds a comment to a file

Parameters:
fileId id of the file to add the comment to
message message for the comment that will be added
Returns:
request to add a comment to a file
    public BoxRequestsFile.AddCommentToFile getAddCommentRequest(String fileIdString message) {
        BoxRequestsFile.AddCommentToFile request = new BoxRequestsFile.AddCommentToFile(fileIdmessagegetCommentUrl(), );
        return request;
    }

    
Gets a request that uploads a file from an input stream

Parameters:
fileInputStream input stream of the file
fileName name of the new file
destinationFolderId id of the parent folder for the new file
Returns:
request to upload a file from an input stream
    public BoxRequestsFile.UploadFile getUploadRequest(InputStream fileInputStreamString fileNameString destinationFolderId){
        BoxRequestsFile.UploadFile request = new BoxRequestsFile.UploadFile(fileInputStreamfileNamedestinationFolderIdgetFileUploadUrl(), );
        return request;
    }

    
Gets a request that uploads a file from an existing file

Parameters:
file file to upload
destinationFolderId id of the parent folder for the new file
Returns:
request to upload a file from an existing file
    public BoxRequestsFile.UploadFile getUploadRequest(File fileString destinationFolderId) {
            BoxRequestsFile.UploadFile request = new BoxRequestsFile.UploadFile(file,  destinationFolderIdgetFileUploadUrl(), );
            return request;
    }

    
Gets a request that uploads a new file version from an input stream

Parameters:
fileInputStream input stream of the new file version
destinationFileId id of the file to upload a new version of
Returns:
request to upload a new file version from an input stream
    public BoxRequestsFile.UploadNewVersion getUploadNewVersionRequest(InputStream fileInputStreamString destinationFileId){
        BoxRequestsFile.UploadNewVersion request = new BoxRequestsFile.UploadNewVersion(fileInputStreamgetFileUploadNewVersionUrl(destinationFileId), );
        return request;
    }

    
Gets a request that uploads a new file version from an existing file

Parameters:
file file to upload as a new version
destinationFileId id of the file to upload a new version of
Returns:
request to upload a new file version from an existing file
    public BoxRequestsFile.UploadNewVersion getUploadNewVersionRequest(File fileString destinationFileId) {
        try {
            BoxRequestsFile.UploadNewVersion request = getUploadNewVersionRequest(new FileInputStream(file), destinationFileId);
            request.setUploadSize(file.length());
            request.setModifiedDate(new Date(file.lastModified()));
            return request;
        } catch (FileNotFoundException e) {
            throw new IllegalArgumentException(e);
        }
    }

    
Gets a request that downloads a given file to a target file

Parameters:
target target file to download to
fileId id of the file to download
Returns:
request to download a file to a target file
Throws:
java.io.IOException
    public BoxRequestsFile.DownloadFile getDownloadRequest(File targetString fileIdthrows IOException{
            if (!target.exists()){
                throw new FileNotFoundException();
            }
            BoxRequestsFile.DownloadFile request = new BoxRequestsFile.DownloadFile(targetgetFileDownloadUrl(fileId),);
            return request;
    }

    
Gets a request that downloads the given file to the provided outputStream. Developer is responsible for closing the outputStream provided.

Parameters:
outputStream outputStream to write file contents to.
fileId the file id to download.
Returns:
request to download a file to an output stream
    public BoxRequestsFile.DownloadFile getDownloadRequest(OutputStream outputStreamString fileId) {
            BoxRequestsFile.DownloadFile request = new BoxRequestsFile.DownloadFile(outputStreamgetFileDownloadUrl(fileId),);
            return request;
    }

    
Gets a request that downloads a thumbnail to a target file

Parameters:
target target file to download thumbnail to
fileId id of file to download the thumbnail of
Returns:
request to download a thumbnail to a target file
Throws:
java.io.IOException
        if (!target.exists()){
            throw new FileNotFoundException();
        }
        return request;
    }

    
Gets a request that downloads the given file thumbnail to the provided outputStream. Developer is responsible for closing the outputStream provided.

Parameters:
outputStream outputStream to write file contents to.
fileId the file id to download.
Returns:
request to download a file thumbnail
        return request;
    }

    
Gets a request that returns a file in the trash

Parameters:
id id of file to get in the trash
Returns:
request to get a file from the trash
        return request;
    }

    
Gets a request that permanently deletes a file from the trash

Parameters:
id id of file to delete from the trash
Returns:
request to permanently delete a file from the trash
        return request;
    }

    
Gets a request that restores a trashed file

Parameters:
id id of file to restore
Returns:
request to restore a file from the trash
        return request;
    }

    
Gets a request that retrieves the comments on a file

Parameters:
id id of the file to retrieve comments for
Returns:
request to retrieve comments on a file
        return request;
    }

    
Gets a request that retrieves the versions of a file

Parameters:
id id of the file to retrieve file versions for
Returns:
request to retrieve versions of a file
        return request;
    }

    
Gets a request that promotes a version to the top of the version stack for a file. This will create a copy of the old version to put on top of the version stack. The file will have the exact same contents, the same SHA1/etag, and the same name as the original. Other properties such as comments do not get updated to their former values.

Parameters:
id id of the file to promote the version of
versionId id of the file version to promote to the top
Returns:
request to promote a version of a file
        return request;
    }

    
Gets a request that deletes a version of a file

Parameters:
id id of the file to delete a version of
versionId id of the file version to delete
Returns:
request to delete a file version
        BoxRequestsFile.DeleteFileVersion request = new BoxRequestsFile.DeleteFileVersion(versionIdgetDeleteFileVersionUrl(idversionId), );
        return request;
    }

    
Gets a request that adds a file to a collection

Parameters:
fileId id of file to add to collection
collectionId id of collection to add the file to
Returns:
request to add a file to a collection
        BoxRequestsFile.AddFileToCollection request = new BoxRequestsFile.AddFileToCollection(fileIdcollectionIdgetFileInfoUrl(fileId), );
        return request;
    }

    
Gets a request that removes a file from a collection

Parameters:
id id of file to delete from the collection
Returns:
request to delete a file from a collection
        return request;
    }
New to GrepCode? Check out our FAQ X