Files
Bridge integrates seamlessly with formidable
to receive and handle files on your server. Simply install formidable
and pass it to initBridge
to enable this feature. You can use the apply
function in Bridge to specify the names of specific files you want your client to send, or use "any" to accept any file.
Install formidable
terminalbash
npm i formidablenpm i --save-dev formidable
terminalbash
npm i formidablenpm i --save-dev formidable
Example
server.tsts
import {initBridge ,handler ,apply } from 'bridge';importformidable from 'formidable';constsendAnyFiles =handler ({files : 'any',resolve : ({files }) => {console .log (files );return {success : true };},});constsendSpecificFiles =handler ({files :apply ('profilePicture', 'coverPicture'),resolve : ({files }) => {console .log (files );return {success : true };},});constroutes = {sendAnyFiles ,sendSpecificFiles ,};constbridge =initBridge ({routes ,formidable });
server.tsts
import {initBridge ,handler ,apply } from 'bridge';importformidable from 'formidable';constsendAnyFiles =handler ({files : 'any',resolve : ({files }) => {console .log (files );return {success : true };},});constsendSpecificFiles =handler ({files :apply ('profilePicture', 'coverPicture'),resolve : ({files }) => {console .log (files );return {success : true };},});constroutes = {sendAnyFiles ,sendSpecificFiles ,};constbridge =initBridge ({routes ,formidable });
Error Example
"If the user submits files with incorrect names, Bridge will respond with a 400 Bad Request error, denoted as "Files schema validation error". Here is an example:
json
{"error": {"status": 400,"name": "Files schema validation error","data": {"missingFiles": ["profilePicture"]}}}
json
{"error": {"status": 400,"name": "Files schema validation error","data": {"missingFiles": ["profilePicture"]}}}