Laravel UploadThing

UploadThing
in package

Table of Contents

Properties

$http  : HttpClient
$apiKey  : string

Methods

__construct()  : mixed
deleteFiles()  : bool
The function `deleteFiles` deletes one or more files by sending a POST request to an API endpoint and returns the response as JSON.
getFileUrls()  : array<string|int, FileUrlList>
The getFileUrls function takes in a string or an array of file keys and returns the file URLs.
getUsageInfo()  : UsageInfo
The function retrieves usage information from an API and returns it as a UsageInfo object.
listFiles()  : FilesList
The function `listFiles` sends a request to the `/api/listFiles` endpoint with optional limit and offset parameters to retrieve a list of files.
renameFiles()  : bool
The function `renameFiles` sends a request to rename files using the provided updates and returns an error message if an unknown error occurs.
upload()  : array<string|int, UploadedData>
The function `upload` takes in one or multiple files, along with optional metadata and content disposition, and uploads them to a server using a POST request.
pollForFileData()  : mixed
requestUT()  : mixed
uploadFile()  : mixed
uploadPart()  : mixed

Properties

Methods

__construct()

public __construct(string $apiKey) : mixed
Parameters
$apiKey : string

deleteFiles()

The function `deleteFiles` deletes one or more files by sending a POST request to an API endpoint and returns the response as JSON.

public deleteFiles(string|array<string|int, string> $keys) : bool
Parameters
$keys : string|array<string|int, string>

The parameter keys can be either a string or an array of strings. It represents the file keys that need to be deleted. If it is a string, it will be converted to an array with a single element. If it is an array, it will be used as is.

Return values
bool

The response from the API endpoint as JSON.

getFileUrls()

The getFileUrls function takes in a string or an array of file keys and returns the file URLs.

public getFileUrls(string|array<string|int, mixed> $keys) : array<string|int, FileUrlList>
Parameters
$keys : string|array<string|int, mixed>
Return values
array<string|int, FileUrlList>

the file URLs for the given keys.

getUsageInfo()

The function retrieves usage information from an API and returns it as a UsageInfo object.

public getUsageInfo() : UsageInfo
Return values
UsageInfo

an instance of the UsageInfo class, which is created from the response received from the requestUT method.

listFiles()

The function `listFiles` sends a request to the `/api/listFiles` endpoint with optional limit and offset parameters to retrieve a list of files.

public listFiles([int|null $limit = null ][, int|null $offset = null ]) : FilesList
Parameters
$limit : int|null = null

The "limit" parameter is used to specify the maximum number of files to be returned in the list. It is an optional parameter, so if it is not provided or set to null, there will be no limit on the number of files returned.

$offset : int|null = null

The offset parameter is used to specify the starting point or position in a list of files. It determines the number of files to skip before starting to return the files. For example, if the offset is set to 10, the function will start returning files from the 11th file onwards.

Return values
FilesList

List of files

renameFiles()

The function `renameFiles` sends a request to rename files using the provided updates and returns an error message if an unknown error occurs.

public renameFiles(array<string|int, mixed> $updates) : bool
Parameters
$updates : array<string|int, mixed>

An array of updates to be made to the files. Each update should be an associative array with the following keys:

  • fileKey - The key of the file to be renamed.
  • newName - The new name of the file.
Return values
bool

The response from the API endpoint as JSON.

upload()

The function `upload` takes in one or multiple files, along with optional metadata and content disposition, and uploads them to a server using a POST request.

public upload(UploadedFile|array<string|int, UploadedFile$files[, array<string|int, mixed> $metadata = [] ][, string $contentDisposition = 'inline' ]) : array<string|int, UploadedData>
Parameters
$files : UploadedFile|array<string|int, UploadedFile>

The files parameter can accept either an UploadedFile object or an array of UploadedFile objects. An UploadedFile object represents a file that has been uploaded through a form.

$metadata : array<string|int, mixed> = []

The metadata parameter is an optional array that allows you to provide additional information or attributes about the uploaded file(s). This can be useful for categorizing or organizing the files, adding tags, or storing any other relevant data associated with the files. The metadata array can contain key-value pairs where the

$contentDisposition : string = 'inline'

The contentDisposition parameter is used to specify how the uploaded file should be handled by the server. It can have two possible values:

  • inline - The file should be displayed inline in the browser, if possible.
  • attachment - The file should be downloaded and saved locally.
Return values
array<string|int, UploadedData>

Uploaded files data

pollForFileData()

private pollForFileData(string $url) : mixed
Parameters
$url : string

requestUT()

private requestUT(string $path[, mixed $data = [] ][, mixed $fallbackErr = "An unknown error occured." ]) : mixed
Parameters
$path : string
$data : mixed = []
$fallbackErr : mixed = "An unknown error occured."
Tags
throws
UploadThingException

uploadFile()

private uploadFile(UploadedFile $file, array<string|int, mixed> $data[, string $contentDisposition = 'inline' ]) : mixed
Parameters
$file : UploadedFile
$data : array<string|int, mixed>
$contentDisposition : string = 'inline'

uploadPart()

private uploadPart(string $url, string $data, string $key, string $type, string $contentDisposition, string $fileName[, int $retry = 0 ][, int $maxRetries = 5 ]) : mixed
Parameters
$url : string
$data : string
$key : string
$type : string
$contentDisposition : string
$fileName : string
$retry : int = 0
$maxRetries : int = 5

        
On this page

Search results