A collection of Header GNDescr objects.
When an EndPoint
requires the ability to upload files, this object tells the internal
Upload-Handler how to upload the files.
IMPORTANT: Upload request must be called as a
POST
,PUT
, orDELETE
method.
dffrnt.api
The system will handle the middleware required to process an upload request, so long as the request-method definition includes this Files object.
During an upload, dffrnt.api
goes through 3 phases:
Files.field
you've defined
contains any filenames.Streams
, and gather any meta-data
. Only
first Files.max(n)
files--if set--will be processed.path
/body
params and meta-data
to the Files.dest
Files.name
callbacks
to determine where, and under what name the file(s) should
be saved.Files.field
param, and a private location
param will be set on the
requests body
which is then passed to your request-method Query
function so the upload
can be logged in your database or whatever post-processing you need done.Uploads are always stored in <project_root>/storage/*
; however, this object
allows you to define which folders within <project_root>/storage/*
the files will go to, how the files will be named, etc.
The name
of the GNParam that represents the <file>
element or files list in the request.
index.html:
<form method="POST" action="...">
<input type="file" name="upload" />
</form>
config/endpoints.cfg.js:
{ // curl -X POST https://host/point -d "username=coolguy" ...
field: 'upload',
} // File is saved to <project_root>/storage/coolguy/*
An optional maximum amount of files that can be pushed to this request. A client can still request
more than the max if the Browser Application allows for it, but the internal uploader will only
upload the first max(n)
files that show up in the filename list.
An optional callback
you can define to determine--based on the parameters it sets--where
in the <project_root>/storage/
folder the file(s) will be saved.
If not defined, any files sent will be saved as <project_root>/storage/<filename>
.
{ // curl -X POST https://host/point -d "username=coolguy" ...
dest(prm, bdy, file) { return bdy.username; },
} // File is saved to <project_root>/storage/coolguy/*
The path-params sent with the request.
The body-params sent with the request.
An object of meta-data retrieved from the uploaded file(s).
An optional callback
you can define to determine--based on the parameters it sets--what
name(s) the file(s) will be saved under.
If not defined, any files sent will be saved as <project_root>/storage(/<destination>)/<originalName>
.
{ // curl -X POST https://host/point/12345" ...
dest(prm, bdy, file) { return 'profile_pics'; },
name(prm, bdy, file) { return prm.user_id; }, // <---
} // File is saved as <project_root>/storage/profile_pics/12345.jpg
The path-params sent with the request.
The body-params sent with the request.
An object of meta-data retrieved from the uploaded file(s).
A collection of Query Examples.
A collection of GNParam objects (for <a href="../classes/_dffrnt_confs.routeau.html">RouteAU_).
Config properties a Route's Documentation.