Documentation

UploadFileDTO extends AbstractBaseDto
in package

UploadFileDTO Class

Data Transfer Object for Canvas LMS file upload initiation. This DTO is used for Step 1 of the Canvas 3-step file upload process.

Usage:

// Direct file upload
$uploadDto = new UploadFileDTO([
    'name' => 'document.pdf',
    'size' => 1024000,
    'content_type' => 'application/pdf',
    'parent_folder_id' => 123,
    'file' => '/path/to/document.pdf'
]);

// File resource upload
$fileResource = fopen('/path/to/file.txt', 'r');
$uploadDto = new UploadFileDTO([
    'name' => 'file.txt',
    'size' => filesize('/path/to/file.txt'),
    'file' => $fileResource
]);

Table of Contents

Properties

$contentType  : string|null
The content type of the file
$file  : mixed
The file to upload (file path, resource, or stream)
$name  : string|null
The filename of the file
$onDuplicate  : string|null
How to handle duplicate filenames
$parentFolderId  : int|null
The id of the folder to store the file in
$parentFolderPath  : string|null
The path of the folder to store the file in
$size  : int|null
The size of the file, in bytes
$submitAssignment  : bool|null
Whether to submit assignment after upload (for assignment submissions)
$url  : string|null
URL for URL-based uploads
$apiPropertyName  : string
The name of the property in the API

Methods

__construct()  : mixed
BaseDto constructor.
autoDetectContentType()  : void
Auto-detect content type from file
autoDetectFileProperties()  : void
Auto-detect all file properties
autoDetectName()  : void
Auto-detect filename from file path
autoDetectSize()  : void
Auto-detect file size
getContentType()  : string|null
Get the content type
getFile()  : mixed
Get the file
getFileResource()  : mixed
Get the file resource for upload
getName()  : string|null
Get the file name
getOnDuplicate()  : string|null
Get the on duplicate setting
getParentFolderId()  : int|null
Get the parent folder ID
getParentFolderPath()  : string|null
Get the parent folder path
getSize()  : int|null
Get the file size
getSubmitAssignment()  : bool|null
Get the submit assignment flag
getUrl()  : string|null
Get the URL
setContentType()  : void
Set the content type
setFile()  : void
Set the file
setName()  : void
Set the file name
setOnDuplicate()  : void
Set the on duplicate setting
setParentFolderId()  : void
Set the parent folder ID
setParentFolderPath()  : void
Set the parent folder path
setSize()  : void
Set the file size
setSubmitAssignment()  : void
Set the submit assignment flag
setUrl()  : void
Set the URL
toApiArray()  : array<string|int, mixed>
Convert the DTO to an array for API requests
toArray()  : array<string|int, mixed>
Convert the DTO to an array
validate()  : bool
Validate the upload data

Properties

$contentType

The content type of the file

public string|null $contentType = null

$file

The file to upload (file path, resource, or stream)

public mixed $file = null

$name

The filename of the file

public string|null $name = null

$onDuplicate

How to handle duplicate filenames

public string|null $onDuplicate = null

$parentFolderId

The id of the folder to store the file in

public int|null $parentFolderId = null

$parentFolderPath

The path of the folder to store the file in

public string|null $parentFolderPath = null

$size

The size of the file, in bytes

public int|null $size = null

$submitAssignment

Whether to submit assignment after upload (for assignment submissions)

public bool|null $submitAssignment = null

$url

URL for URL-based uploads

public string|null $url = null

$apiPropertyName

The name of the property in the API

protected string $apiPropertyName = ''

Methods

__construct()

BaseDto constructor.

public __construct(array<string|int, mixed> $data) : mixed
Parameters
$data : array<string|int, mixed>
Tags
throws
Exception

autoDetectContentType()

Auto-detect content type from file

public autoDetectContentType() : void

autoDetectFileProperties()

Auto-detect all file properties

public autoDetectFileProperties() : void

This method optimizes file system access by checking file existence once and reusing that information for all auto-detection operations.

autoDetectName()

Auto-detect filename from file path

public autoDetectName() : void

autoDetectSize()

Auto-detect file size

public autoDetectSize() : void

getContentType()

Get the content type

public getContentType() : string|null
Return values
string|null

getFileResource()

Get the file resource for upload

public getFileResource() : mixed

IMPORTANT: When this method returns a file resource (from fopen), the caller is responsible for closing it after use to prevent resource leaks. The File API class handles this automatically during the upload process.

Tags
throws
Exception
Return values
mixed

File resource, string path, or other file object

getName()

Get the file name

public getName() : string|null
Return values
string|null

getOnDuplicate()

Get the on duplicate setting

public getOnDuplicate() : string|null
Return values
string|null

getParentFolderId()

Get the parent folder ID

public getParentFolderId() : int|null
Return values
int|null

getParentFolderPath()

Get the parent folder path

public getParentFolderPath() : string|null
Return values
string|null

getSize()

Get the file size

public getSize() : int|null
Return values
int|null

getSubmitAssignment()

Get the submit assignment flag

public getSubmitAssignment() : bool|null
Return values
bool|null

getUrl()

Get the URL

public getUrl() : string|null
Return values
string|null

setContentType()

Set the content type

public setContentType(string|null $contentType) : void
Parameters
$contentType : string|null

setFile()

Set the file

public setFile(mixed $file) : void
Parameters
$file : mixed

setName()

Set the file name

public setName(string|null $name) : void
Parameters
$name : string|null

setOnDuplicate()

Set the on duplicate setting

public setOnDuplicate(string|null $onDuplicate) : void
Parameters
$onDuplicate : string|null

setParentFolderId()

Set the parent folder ID

public setParentFolderId(int|null $parentFolderId) : void
Parameters
$parentFolderId : int|null

setParentFolderPath()

Set the parent folder path

public setParentFolderPath(string|null $parentFolderPath) : void
Parameters
$parentFolderPath : string|null

setSize()

Set the file size

public setSize(int|null $size) : void
Parameters
$size : int|null

setSubmitAssignment()

Set the submit assignment flag

public setSubmitAssignment(bool|null $submitAssignment) : void
Parameters
$submitAssignment : bool|null

setUrl()

Set the URL

public setUrl(string|null $url) : void
Parameters
$url : string|null

toApiArray()

Convert the DTO to an array for API requests

public toApiArray() : array<string|int, mixed>

NOTE: This method intentionally differs from AbstractBaseDto::toApiArray() because file uploads require multipart/form-data format without the apiPropertyName prefix (e.g., 'file[name]'). Canvas file upload API expects flat field names in multipart requests.

Tags
throws
Exception
Return values
array<string|int, mixed>

toArray()

Convert the DTO to an array

public toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

validate()

Validate the upload data

public validate() : bool
Tags
throws
Exception
Return values
bool

        
On this page

Search results