Package cn.leancloud

Class LCFile


public final class LCFile extends LCObject
  • Field Details

  • Constructor Details

    • LCFile

      public LCFile()
      default constructor.
    • LCFile

      public LCFile(String name, byte[] data)
      constructor with name and data.
      Parameters:
      name - file name.
      data - binary data.
    • LCFile

      public LCFile(String name, File localFile)
      constructor with name and local file.
      Parameters:
      name - file name.
      localFile - local file.
    • LCFile

      public LCFile(String name, String url)
      constructor with name and external url.
      Parameters:
      name - file name.
      url - external url.
    • LCFile

      public LCFile(String name, String url, Map<String,Object> metaData)
      constructor with name and external url.
      Parameters:
      name - file name
      url - external url.
      metaData - additional attributes.
    • LCFile

      protected LCFile(String name, String url, Map<String,Object> metaData, boolean external)
  • Method Details

    • setUploadHeader

      public static void setUploadHeader(String key, String value)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class LCObject
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class LCObject
    • withObjectIdInBackground

      public static io.reactivex.Observable<LCFile> withObjectIdInBackground(String objectId)
      Get AVFile instance from objectId.
      Parameters:
      objectId - file objectId.
      Returns:
      observable instance.
    • getName

      public String getName()
      Get file name.
      Returns:
      file name.
    • setName

      public void setName(String name)
      Set file name.
      Parameters:
      name - file name.
    • setPathPrefix

      public void setPathPrefix(String path)
      set folder path
      Parameters:
      path - folder path. null or empty string equals to clearPathPrefix.
    • clearPathPrefix

      public void clearPathPrefix()
      clear folder path.
    • getMetaData

      public Map<String,Object> getMetaData()
      Get file meta data.
      Returns:
      meta data.
    • setMetaData

      public void setMetaData(Map<String,Object> metaData)
      Set file meta data.
      Parameters:
      metaData - meta data.
    • addMetaData

      public void addMetaData(String key, Object val)
      Add new meta data.
      Parameters:
      key - meta key.
      val - meta value.
    • getMetaData

      public Object getMetaData(String key)
      Get file meta data.
      Parameters:
      key - meta key.
      Returns:
      meta value.
    • removeMetaData

      public Object removeMetaData(String key)
      Remove file meta data.
      Parameters:
      key - meta key.
      Returns:
      old value.
    • clearMetaData

      public void clearMetaData()
      Cleanup meta data.
    • getSize

      public int getSize()
      Get file size.
      Returns:
      file size.
    • getMimeType

      public String getMimeType()
      Get file mime type.
      Returns:
      mime type.
    • setMimeType

      public void setMimeType(String mimeType)
      Set file mime type.
      Parameters:
      mimeType - mime type.
    • getKey

      public String getKey()
      Get file key.
      Returns:
      file key.
    • getBucket

      public String getBucket()
      Get file bucket.
      Returns:
      file bucket.
    • getUrl

      public String getUrl()
      Get file url.
      Returns:
      file url.
    • getProvider

      public String getProvider()
      Get file provider.
      Returns:
      file provider.
    • put

      public void put(String key, Object value)
      Set file attribute.
      Overrides:
      put in class LCObject
      Parameters:
      key - attribute key.
      value - attribute value. notice: UnsupportedOperationException
    • get

      public Object get(String key)
      Get file attribute.
      Overrides:
      get in class LCObject
      Parameters:
      key - attribute key.
      Returns:
      attribute value. notice: UnsupportedOperationException
    • remove

      public void remove(String key)
      Remove file attribute.
      Overrides:
      remove in class LCObject
      Parameters:
      key - attribute key. notice: UnsupportedOperationException
    • increment

      public void increment(String key)
      Increment file attribute.
      Overrides:
      increment in class LCObject
      Parameters:
      key - attribute key. notice: UnsupportedOperationException
    • increment

      public void increment(String key, Number value)
      Increment file attribute.
      Overrides:
      increment in class LCObject
      Parameters:
      key - attribute key.
      value - step value. notice: UnsupportedOperationException
    • getThumbnailUrl

      public String getThumbnailUrl(boolean scaleToFit, int width, int height)
      Returns a thumbnail image url using QiNiu endpoints.
      Parameters:
      scaleToFit - scale param.
      width - width.
      height - height.
      Returns:
      new url for thumbnail.
      See Also:
    • getThumbnailUrl

      public String getThumbnailUrl(boolean scaleToFit, int width, int height, int quality, String fmt)
      Returns a thumbnail image url using QiNiu endpoints.
      Parameters:
      scaleToFit - scale param.
      width - width
      height - height
      quality - quality.
      fmt - format string.
      Returns:
      new url for thumbnail.
    • toMap

      public Map<String,Object> toMap()
      Get map data of current file.
      Returns:
      map data.
    • saveInBackground

      public void saveInBackground(boolean keepFileName, ProgressCallback progressCallback)
      save to cloud backend.
      Parameters:
      keepFileName - whether keep file name in url or not.
      progressCallback - progress callback.
    • saveInBackground

      public void saveInBackground(LCUser asAuthenticatedUser, boolean keepFileName, ProgressCallback progressCallback)
      save to cloud in background.
      Parameters:
      asAuthenticatedUser - explicit user for request authentication.
      keepFileName - whether keep file name in url or not.
      progressCallback - progress callback. in general, this method should be invoked in lean engine.
    • saveInBackground

      public void saveInBackground(ProgressCallback progressCallback)
      save to cloud backend.
      Parameters:
      progressCallback - progress callback.
    • saveInBackground

      public io.reactivex.Observable<LCFile> saveInBackground()
      save to cloud backend.
      Overrides:
      saveInBackground in class LCObject
      Returns:
      Observable object.
    • save

      public void save()
      save to cloud.
      Overrides:
      save in class LCObject
    • save

      public void save(LCUser asAuthenticatedUser)
      save to cloud
      Overrides:
      save in class LCObject
      Parameters:
      asAuthenticatedUser - explicit user for request authentication.
    • saveInBackground

      public io.reactivex.Observable<LCFile> saveInBackground(boolean keepFileName)
      save to cloud backend.
      Parameters:
      keepFileName - whether keep file name in url or not.
      Returns:
      Observable object.
    • saveEventually

      public void saveEventually() throws LCException
      Save eventually(not supported).
      Overrides:
      saveEventually in class LCObject
      Throws:
      LCException - exception happened. Because that file size is too big, cache the entire data will cost much disk capacity, so we don't support this method at present.
    • saveEventually

      public void saveEventually(LCUser asAuthenticatedUser) throws LCException
      Save eventually(not supported).
      Overrides:
      saveEventually in class LCObject
      Parameters:
      asAuthenticatedUser - explicit user for request authentication.
      Throws:
      LCException - exception happened. Because that file size is too big, cache the entire data will cost much disk capacity, so we don't support this method at present.
    • saveInBackground

      public io.reactivex.Observable<LCFile> saveInBackground(LCUser asAuthenticatedUser, boolean keepFileName)
      save to cloud in background.
      Parameters:
      asAuthenticatedUser - explicit user for request authentication.
      keepFileName - whether keep file name in url or not.
      Returns:
      Observable object. in general, this method should be invoked in lean engine.
    • getData

      public byte[] getData()
      Get data in blocking mode.
      Returns:
      data bytes.
    • getDataInBackground

      public io.reactivex.Observable<byte[]> getDataInBackground()
      Get data in async mode.
      Returns:
      observable instance.
    • getDataStream

      public InputStream getDataStream() throws Exception
      Get data stream in blocking mode.
      Returns:
      data stream.
      Throws:
      Exception - for file not found or io problem.
    • getDataStreamInBackground

      public io.reactivex.Observable<InputStream> getDataStreamInBackground()
      Get data stream in async mode.
      Returns:
      observable instance.
    • withAbsoluteLocalPath

      public static LCFile withAbsoluteLocalPath(String name, String absoluteLocalFilePath) throws FileNotFoundException
      Generate File instance with local path.
      Parameters:
      name - file name
      absoluteLocalFilePath - local path.
      Returns:
      file instance.
      Throws:
      FileNotFoundException - file not found.
    • withFile

      public static LCFile withFile(String name, File file) throws FileNotFoundException
      Generate File instance with local file.
      Parameters:
      name - file name.
      file - local file.
      Returns:
      file instance.
      Throws:
      FileNotFoundException - file not found.