web.files

web.files

web.files

Function

Read the uploaded file object.

Syntax

Parameters

No parameters.

Return value

TypeDescription
ObjectReturns the upload file field object. The object key is the form file field name, and the value is the field upload file information array.

Object structure

The top-level objects of web.files are grouped by upload field names. Even if only one file is uploaded for the same field, the field value will still be an Array.

FieldTypeDescription
Any upload field nameArrayArray of file information objects under this field. When the field does not exist, the read result is Empty.

Each file information object contains the following fields:

FieldTypeDescription
filenameStringThe original file name submitted by the browser; if there is no file name, it is an empty string.
sizeIntThe number of bytes of the uploaded file.
typeStringThe MIME type of the uploaded file; an empty string if no type is provided in the request.
pathStringThe local temporary file path of the server after BT is saved.
nameStringForm file field name, such as avatar, file.
fileFsThe fs object bound to path can continue to call read, binary, move, copy, delete and other fs methods.

Example

The file field can be directly used as an fs object to process the uploaded temporary file:

Notes

  • web.files only contains file fields; for normal form fields, please read web.post.
  • The uploaded file will be saved to the temporary directory of the server first. path and file point to the saved local file.
  • file.move(dir) will move the temporary file to the target directory and return the new Fs object; the return value should be used to continue accessing the moved file.