web.files
web.files
Function
Read the uploaded file object.
Syntax
web.files
Parameters
No parameters.
Return value
| Type | Description |
|---|---|
| Object | Returns 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.
| Field | Type | Description |
|---|---|---|
| Any upload field name | Array | Array 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:
| Field | Type | Description |
|---|---|---|
| filename | String | The original file name submitted by the browser; if there is no file name, it is an empty string. |
| size | Int | The number of bytes of the uploaded file. |
| type | String | The MIME type of the uploaded file; an empty string if no type is provided in the request. |
| path | String | The local temporary file path of the server after BT is saved. |
| name | String | Form file field name, such as avatar, file. |
| file | Fs | The fs object bound to path can continue to call read, binary, move, copy, delete and other fs methods. |
Example
// Upload field avatar avatar = web.files.avatar[0] result = avatar.filename // Output: logo.png print result
The file field can be directly used as an fs object to process the uploaded temporary file:
avatar = web.files.avatar[0] saved = avatar.file.move('uploads') result = saved.path() // Example output: uploads/avatar.png print result
Notes
-
web.filesonly contains file fields; for normal form fields, please readweb.post. - The uploaded file will be saved to the temporary directory of the server first.
pathandfilepoint 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.