Overview

Namespaces

  • LeanCloud
    • Engine
    • Operation
    • Storage
    • Uploader

Classes

  • ACL
  • AppRouter
  • Bytes
  • Client
  • File
  • GeoPoint
  • LeanObject
  • MIMEType
  • Push
  • Query
  • Region
  • Relation
  • Role
  • RouteCache
  • SaveOption
  • SMS
  • User

Exceptions

  • BatchRequestError
  • CloudException
  • Overview
  • Namespace
  • Class

Class File

File object on LeanCloud

Namespace: LeanCloud
Located at LeanCloud/File.php
Methods summary
public
# __construct( string $name, mixed $data = null, string $mimeType = null )

Initialize file

Initialize file

Parameters

$name
File base name
$data
(optional) File content
$mimeType
(optional) Mime type
public static LeanCloud\File
# createWithUrl( string $name, string $url, string $mimeType = null )

Create file with public external URL

Create file with public external URL

Parameters

$name
File base name
$url
Public URL
$mimeType
(optional)

Returns

LeanCloud\File
public static LeanCloud\File
# createWithData( string $name, string $data, string $mimeType = null )

Create file with raw data

Create file with raw data

Parameters

$name
File name
$data
File content
$mimeType

Returns

LeanCloud\File
public static LeanCloud\File
# createWithLocalFile( string $filepath, string $mimeType = null, string $name = null )

Create file from disk

Create file from disk

Parameters

$filepath
Absolute file path
$mimeType
E.g. "image/png"
$name
Name of file

Returns

LeanCloud\File

Throws

RuntimeException
public mixed
# get( string $key )

Get file attribute

Get file attribute

Parameters

$key

Returns

mixed
public string
# getName( )

Get name of file

Get name of file

Returns

string
public string
# getKey( )

Get key of file

Get key of file

Returns

string
public LeanCloud\File
# setKey( $val )

Set key of file

Set key of file

Returns

LeanCloud\File
public string
# getObjectId( )

Get objectId of file

Get objectId of file

Returns

string
public DateTime
# getCreatedAt( )

Returns

DateTime
public DateTime
# getUpdatedAt( )

Returns

DateTime
public string
# getMimeType( )

Get file MIME type

Get file MIME type

Returns

string
public string
# getUrl( )

Get file url

Get file url

Returns

string
public string
# getThumbUrl( float|integer $width, float|integer $height, float|integer $quality = 100, boolean $scaleToFit = true, string $format = "png" )

Get thumbnail URL

Get thumbnail URL

It returns a URL that could be used to display file thumbnail on client. The thumbnail will be generated on-the-fly when request arrives.

Parameters

$width
Image width
$height
Image height
$quality
Image quality factor between 0 ~ 100
$scaleToFit
Scale to fit, or cut to fit
$format
Image format: gif, png, webp etc.

Returns

string
public integer
# getSize( )

Get file size

Get file size

Returns

integer
public string|null
# getOwnerId( )

Get id of uploaded user

Get id of uploaded user

Returns

string|null
public LeanCloud\File
# setMeta( string $key, miexed $val )

Set meta data

Set meta data

Parameters

$key
$val

Returns

LeanCloud\File
public mixed
# getMeta( string $key = null )

Get meta data

Get meta data

It returns all metaData if key is null

Parameters

$key

Returns

mixed
public
# mergeAfterSave( array $data )

Merge server response after save

Merge server response after save

Parameters

$data
JSON decoded response
public
# mergeAfterFetch( array $data )

Merge server response after fetch

Merge server response after fetch

Parameters

$data
JSON decoded response
public boolean
# isDirty( )

If there are unsaved changes.

If there are unsaved changes.

Returns

boolean
public
# save( )

Save file on the cloud

Save file on the cloud

Throws

LeanCloud\CloudException
public static LeanCloud\File
# fetch( $objectId )

Fetch file object by id

Fetch file object by id

Note it fetches descriptive data from LeanCloud, but not file content. The content should be fetched from file URL.

Returns

LeanCloud\File
public
# destroy( )

Delete file on cloud

Delete file on cloud

Throws

LeanCloud\CloudException
public array
# encode( )

Encode to JSON representation

Encode to JSON representation

Returns

array
API documentation generated by ApiGen