new UploadService(server, route, upload_directory, upload_link, callbackopt)
- Description:
Implements a file upload of the server
-
A POST service is attached to the given route.
-
When an upload post is sent on the given route for a file of name
$filename.$extension
- The file is stored with the path
$uploadPath=$upload_directory/$now-$filename.$extension
on the server- where
$now
stands for the file creation number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
- where
- The file is stored with the path
-
On success the original page (via the header referer value) is reloaded, adding a
upload-path=$file-path
parameter to the query. -
On the client side it has to be implemented via a construct of the form:
<form action='$upload-service-url' method='post' encType='multipart/form-data'> <input type='file' name='uploadFile'/> <input type='submit'/> </form>
where the
name='uploadFile'
reference is mandatory.- On the client side a construct of the form:
let uploadPath = new URLSearchParams(window.location.search).get("upload-path"); if (uploadPath != undefined) console.log("The file ``" + uploadPath + "ยดยด has been uploaded");
can be used to detect if the file has been properly loaded.
-
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
server |
express | The express server mechanism. |
||
route |
string |
/upload
|
The service route. |
|
upload_directory |
string |
./upload
|
The directory storing the uploaded files. |
|
upload_link |
string | If defined a link of path |
||
callback |
callback |
<optional> |
function(uploadPath){}
|
The callback called after uploading. |