Class: UploadedFile
Class: UploadedFile
Class representing an UploadedFile.
Author
Mr. Stone evensstone@gmail.com
Extends
Constructors
Constructor
new UploadedFile(
path,
originalName,
mimeType?,
checkPath?): UploadedFile;
Create an UploadedFile.
Parameters
path
string
The file path.
originalName
string
The original name of the uploaded file.
mimeType?
string
The MIME type of the file.
checkPath?
boolean
= true
Returns
UploadedFile
Overrides
Methods
edit()
edit(callback): this;
Edit file content.
Parameters
callback
(content
) => string
The callback function to modify the file content.
Returns
this
The current File instance.
Inherited from
exists()
exists(): boolean;
Check if the file exists.
Returns
boolean
True if the file exists, otherwise false.
Inherited from
getAbsolutePath()
getAbsolutePath(root): string;
Get the absolute file path.
Parameters
root
string
= ''
The root directory to resolve from.
Returns
string
The absolute file path.
Inherited from
getATime()
getATime(): undefined | number | bigint;
Get the last access time of the file.
Returns
undefined
| number
| bigint
The last access time in milliseconds.
Inherited from
getBasename()
getBasename(exclude): string;
Get the basename of the file.
Parameters
exclude
string
= ''
The file extension to exclude from the basename.
Returns
string
The basename of the file.
Inherited from
getClientMimeType()
getClientMimeType(): string;
Get the MIME type of the uploaded file.
Returns
string
The MIME type of the file.
getClientOriginalExtension()
getClientOriginalExtension(): string;
Get the original file extension of the uploaded file.
Returns
string
The original file extension.
getClientOriginalName()
getClientOriginalName(): string;
Get the original name of the uploaded file.
Returns
string
The original name of the file.
getContent()
getContent(encoding): string;
Get file content.
Parameters
encoding
BufferEncoding
= 'utf-8'
Returns
string
The content of the file as a string.
Inherited from
getCTime()
getCTime(): undefined | number | bigint;
Get the created time of the file.
Returns
undefined
| number
| bigint
The created time in milliseconds.
Inherited from
getDirname()
getDirname(): string;
Get the directory name of the file.
Returns
string
The directory name.
Inherited from
getEncodedAbsolutePath()
getEncodedAbsolutePath(root): string;
Get the encoded absolute file path.
Parameters
root
string
= ''
The root directory to resolve from.
Returns
string
The encoded absolute file path.
Inherited from
getEncodedPath()
getEncodedPath(): string;
Get the encoded file path.
Returns
string
The encoded file path.
Inherited from
getExtension()
getExtension(): string;
Get the file extension.
Returns
string
The file extension.
Inherited from
getFilename()
getFilename(): string;
Get the filename of the file.
Returns
string
The filename of the file.
Inherited from
getHashedContent()
getHashedContent(algo): string;
Get the hashed content of the file.
Parameters
algo
string
= 'sha256'
The hashing algorithm to use.
Returns
string
The hashed content of the file as a hex string.
Inherited from
getMimeType()
Get the MIME type of the file.
Param
A fallback MIME type if detection fails.
Call Signature
getMimeType(): undefined | string;
Get the MIME type of the file.
Returns
undefined
| string
The MIME type of the file.
Param
A fallback MIME type if detection fails.
Inherited from
Call Signature
getMimeType(fallback): string;
Get the MIME type of the file.
Parameters
fallback
string
A fallback MIME type if detection fails.
Returns
string
The MIME type of the file.
Param
A fallback MIME type if detection fails.
Inherited from
getMTime()
getMTime(): undefined | number | bigint;
Get the last modified time of the file.
Returns
undefined
| number
| bigint
The last modified time in milliseconds.
Inherited from
getName()
getName(): string;
Get the name of the file without extension.
Returns
string
The name of the file.
Inherited from
getPath()
getPath(): string;
Get the file path.
Returns
string
The file path.
Inherited from
getSize()
getSize(formatted): undefined | string | number | bigint;
Get file size.
Parameters
formatted
boolean
= false
Whether to return the file size as a formatted string.
Returns
undefined
| string
| number
| bigint
The file size as a string or number.
Inherited from
guessClientExtension()
guessClientExtension(): undefined | string;
Guess the client file extension based on the MIME type.
Returns
undefined
| string
The guessed file extension.
isAbsolute()
isAbsolute(): boolean;
Check if the file path is absolute.
Returns
boolean
True if the file path is absolute, otherwise false.
Inherited from
isCompressed()
isCompressed(extensions): boolean;
Check if the file is compressed.
Parameters
extensions
string
[] = ...
Returns
boolean
True if the file is compressed, otherwise false.
Inherited from
isDir()
isDir(): boolean;
Check if the file is a directory.
Returns
boolean
True if the file is a directory, otherwise false.
Inherited from
isExecutable()
isExecutable(): boolean;
Check if the file is executable.
Returns
boolean
True if the file is executable, otherwise false.
Inherited from
isFile()
isFile(): boolean;
Check if the file is a regular file.
Returns
boolean
True if the file is a regular file, otherwise false.
Inherited from
isLink()
isLink(): boolean;
Check if the file is a symbolic link.
Returns
boolean
True if the file is a symbolic link, otherwise false.
Inherited from
isPathPrefix()
isPathPrefix(prefix): boolean;
Check if the file path starts with a provided prefix.
Parameters
prefix
string
Returns
boolean
True if the file path starts with the provided prefix, otherwise false.
Inherited from
isReadable()
isReadable(): boolean;
Check if the file is readable.
Returns
boolean
True if the file is readable, otherwise false.
Inherited from
isValid()
isValid(): boolean;
Check if the uploaded file is valid.
Returns
boolean
True if the file exists, otherwise false.
isWritable()
isWritable(): boolean;
Check if the file is writable.
Returns
boolean
True if the file is writable, otherwise false.
Inherited from
move()
move(directory, name?): this;
Move the uploaded file to a new directory.
Parameters
directory
string
The target directory.
name?
string
The new name for the file.
Returns
this
The current UploadedFile instance.
Throws
FileError if the file is not valid.
Overrides
remove()
remove(force): this;
Remove file.
Parameters
force
boolean
= false
Whether to forcefully remove the file.
Returns
this
The current File instance.
Inherited from
write()
write(content): this;
Write content to file.
Parameters
content
string
The content to write to the file.
Returns
this
The current File instance.
Inherited from
create()
static create(path, checkPath): File;
Create a File.
Parameters
path
string
The file path.
checkPath
boolean
= true
Whether to check if the file path is valid.
Returns
A new File instance.
Inherited from
createFile()
static createFile(
path,
originalName,
mimeType?,
checkPath?): UploadedFile;
Create an UploadedFile.
Parameters
path
string
The file path.
originalName
string
The original name of the uploaded file.
mimeType?
string
The MIME type of the file.
checkPath?
boolean
= true
Returns
UploadedFile
A new UploadedFile instance.