You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/index.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,7 @@ description: Documentation and developer's resources for Fano Framework, web app
28
28
29
29
-[Working with Request](/working-with-request). It explains how to get query string parameters, read POST data and work with file upload.
30
30
-[Working with Response](/working-with-response). It explains how to return response in various format such as HTML, JSON or binary response, for example, image.
31
+
-[Handling File Upload](/handling-file-upload). It explains how to work with file upload.
31
32
-[Working with Session](/working-with-session). It explains how to manage state between requests.
To retrieve file uploaded by client, you need to call `getUploadedFile()`. It returns data of type `IUploadedFileArray` which array of `IUploadedFile` instance.
27
+
28
+
29
+
```
30
+
var myFile : IUploadedFileArray;
31
+
...
32
+
myFile := request.getUploadedFile('myFile');
33
+
```
34
+
35
+
Client can send one or more file with same name, for example:
If client upload one or more files, `length(myFile)` will indicates how many
47
+
files actually uploaded.
48
+
49
+
## Move uploaded file
50
+
51
+
Initially, uploaded file will be stored in system temporary directory. You need to
52
+
call `moveTo()` methods to move into permanent location.
53
+
54
+
```
55
+
if (length(myFile) > 0) then
56
+
begin
57
+
myFile[0].moveTo(targetUploadPath);
58
+
end;
59
+
```
60
+
`targetUploadPath` is full filename (including its target directory). You must make sure that `targetUploadPath` is writeable. Exception `EInOutError` is raised when
61
+
uploaded file can not be written to target path.
62
+
63
+
## Get uploaded file size
64
+
65
+
Size of uploaded file in octet (or bytes) can be queried with `size()` method.
66
+
67
+
```
68
+
var fSize : int64;
69
+
...
70
+
fSize := myFile[0].size();
71
+
```
72
+
73
+
## Get file MIME type
74
+
75
+
MIME type of uploaded file can be queried with `getClientMediaType()` method.
76
+
For example, if upload JPEG image, you may get `image/jpeg`.
77
+
78
+
```
79
+
var mime : string;
80
+
...
81
+
mime := myFile[0].getClientMediaType();
82
+
```
83
+
84
+
If client does not send any MIME type (aka Content Type) then it is assumed
85
+
`application/octet-stream`.
86
+
87
+
## Get original file name
88
+
89
+
To get original file name of uploaded file use `getClientFilename()` method.
90
+
91
+
```
92
+
var filename : string;
93
+
...
94
+
filename := myFile[0].getClientFilename();
95
+
```
96
+
97
+
If client does not send filename then it returns empty string.
98
+
99
+
For example how to handle file upload with Fano Framework, see
Fano Framework validation feature provides several built-in validation rule that you can use to [validate against file upload](/security/form-validation/built-in-validation-rules#uploaded-file) such as to verify that field is indeed a file upload, to verify that file upload match certain MIME type or more advanced use such as antivirus scan validation or file format validation.
Above method search query string parameter first. If it cannot find data with key `msg1`, it tries to read body parameters. If none found, default value 'ok` is returned.
To retrieve file uploaded by client, you need to call `getUploadedFile()`. It returns data of type `IUploadedFileArray` which array of `IUploadedFile` instance.
146
-
147
-
148
-
```
149
-
var myFile : IUploadedFileArray;
150
-
...
151
-
myFile := request.getUploadedFile('myFile');
152
-
```
153
-
154
-
Client can send one or more file with same name, for example:
If client upload one or more files, `length(myFile)` will indicates how many
166
-
files actually uploaded.
167
-
168
-
### Move uploaded file
169
-
170
-
Initially, uploaded file will be stored in system temporary directory. You need to
171
-
call `moveTo()` methods to move into permanent location.
172
-
173
-
```
174
-
if (length(myFile) > 0) then
175
-
begin
176
-
myFile[0].moveTo(targetUploadPath);
177
-
end;
178
-
```
179
-
`targetUploadPath` is full filename (including its target directory). You must make sure that `targetUploadPath` is writeable. Exception `EInOutError` is raised when
180
-
uploaded file can not be written to target path.
181
-
182
-
### Get uploaded file size
127
+
To get request headers, use `headers()` methods of `IRequest`. It returns instance of `IReadOnlyHeaders` interface.
183
128
184
-
Size of uploaded file in octet (or bytes) can be queried with `size()` method.
129
+
To read request header value, call `getHeader()` method and pass header to read. For example to read `Accept-Language` header value,
0 commit comments