File Upload
BFF combined with runtime framework provides file upload capabilities, supporting integrated calls and pure function manual calls.
BFF Function
First, create the api/lambda/upload.ts file:
api/lambda/upload.ts
Tip
The formData parameter in the interface processing function can access files uploaded from the client side. It is an Object where the keys correspond to the field names used during the upload.
Integrated Calling
Next, directly import and call the function in src/routes/upload/page.tsx:
routes/upload/page.tsx
Tip
Note: The input parameter type must be { formData: FormData } for the upload to succeed.
Manual Calling
You can manually upload files using the fetch API, when calling fetch, set the body as FormData type and submit a post request.
routes/upload/page.tsx