Class ModuleUploads


  • public class ModuleUploads
    extends java.lang.Object
    Upload Module.

    This module will take care of all `upload.contentful.com` related issues, as in directly uploading a file to Contentful, receiving its id.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  ModuleUploads.Async
      Async module.
    • Constructor Summary

      Constructors 
      Constructor Description
      ModuleUploads​(retrofit2.Retrofit retrofit, java.util.concurrent.Executor callbackExecutor, java.lang.String spaceId, java.lang.String environmentId, boolean environmentIdConfigured)
      Create uploads module.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ModuleUploads.Async async()  
      CMAUpload create​(java.io.InputStream stream)
      Create a new upload on the configured space.
      CMAUpload create​(java.io.InputStream stream, int chunkSize)  
      CMAUpload create​(java.lang.String spaceId, java.lang.String environmentId, java.io.InputStream stream)  
      CMAUpload create​(java.lang.String spaceId, java.lang.String environmentId, java.io.InputStream stream, int chunkSize)
      Create a new upload.
      protected com.contentful.java.cma.ServiceUploads createService​(retrofit2.Retrofit retrofit)  
      int delete​(CMAUpload upload, java.lang.String environmentId)
      Delete a given upload again.
      CMAUpload fetchOne​(java.lang.String uploadId, java.lang.String environmentId)
      Get information about a given upload on the configured space.
      CMAUpload fetchOne​(java.lang.String spaceId, java.lang.String environmentId, java.lang.String uploadId)
      Get information about the given upload.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ModuleUploads

        public ModuleUploads​(retrofit2.Retrofit retrofit,
                             java.util.concurrent.Executor callbackExecutor,
                             java.lang.String spaceId,
                             java.lang.String environmentId,
                             boolean environmentIdConfigured)
        Create uploads module.
        Parameters:
        retrofit - the retrofit instance to be used to create the service.
        callbackExecutor - to tell on which thread it should run.
        spaceId - the space to be used when not given.
        environmentId - the environment to be used when not given.
        environmentIdConfigured - internal helper to see if environment was set.
    • Method Detail

      • createService

        protected com.contentful.java.cma.ServiceUploads createService​(retrofit2.Retrofit retrofit)
      • create

        public CMAUpload create​(java.io.InputStream stream)
                         throws java.io.IOException
        Create a new upload on the configured space.

        Once an upload is created, you can use it in ModuleAssets through CMAClient.assets() for creating an asset based on a local file.

        Parameters:
        stream - the actual binary representation of the upload. Cannot be null.
        Returns:
        the upload created, containing the id to be used further on.
        Throws:
        java.lang.IllegalArgumentException - if spaceId is null.
        java.lang.IllegalArgumentException - if stream is null.
        java.io.IOException - if the stream could not be read.
        CMANotWithEnvironmentsException - if environmentId was set using CMAClient.Builder.setEnvironmentId(String).
        See Also:
        CMAClient.Builder.setSpaceId(String)
      • create

        public CMAUpload create​(java.io.InputStream stream,
                                int chunkSize)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • create

        public CMAUpload create​(java.lang.String spaceId,
                                java.lang.String environmentId,
                                java.io.InputStream stream)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • create

        public CMAUpload create​(java.lang.String spaceId,
                                java.lang.String environmentId,
                                java.io.InputStream stream,
                                int chunkSize)
                         throws java.io.IOException
        Create a new upload.

        Once an upload is created, you can use it in ModuleAssets through CMAClient.assets() for creating an asset based on a local file.

        This method will override the configuration specified through CMAClient.Builder.setSpaceId(String) and will ignore CMAClient.Builder.setEnvironmentId(String).

        Parameters:
        spaceId - a nonnull id representing the space to add the upload to.
        stream - the actual binary representation of the upload. Cannot be null.
        Returns:
        the upload created, containing the id to be used further on.
        Throws:
        java.lang.IllegalArgumentException - if spaceId is null.
        java.lang.IllegalArgumentException - if stream is null.
        java.io.IOException - if the stream could not be read.
      • fetchOne

        public CMAUpload fetchOne​(java.lang.String spaceId,
                                  java.lang.String environmentId,
                                  java.lang.String uploadId)
        Get information about the given upload.

        This method will override the configuration specified through CMAClient.Builder.setSpaceId(String) and will ignore CMAClient.Builder.setEnvironmentId(String).

        Parameters:
        spaceId - which space is this upload hosted under?
        uploadId - what id does the upload have?
        Returns:
        an CMAUpload based on this id and space combination.
        Throws:
        java.lang.IllegalArgumentException - if spaceId is null.
        java.lang.IllegalArgumentException - if uploadId is null.
      • delete

        public int delete​(CMAUpload upload,
                          java.lang.String environmentId)
        Delete a given upload again.
        Parameters:
        upload - upload
        Returns:
        response code, 204 on success.
        Throws:
        java.lang.IllegalArgumentException - if spaceId is null.
        java.lang.IllegalArgumentException - if uploadId is null.
      • async

        public ModuleUploads.Async async()
        Returns:
        a module with a set of asynchronous methods.