Ujjwal Gupta
Dec 31, 2023

--

This implementation is very easy in fortjs - just grab your file with the name and do whatever you want to.

import { Controller, textResult, http } from "fortjs";

import * as Path from "path";

export class FileController extends Controller {

@http.post("/upload")

async uploadFile() {

let result;

// Check if a file exists in the HTTP request

if (this.file.isExist('jsstore') === true) {

// Save the file to the desired location

const pathToSave = Path.join(__dirname, "../upload.png");

// Supply the filename from the request and the path to save

await this.file.saveTo('jsstore', pathToSave);

result = "File saved";

} else {

result = "File not saved";

}

return textResult(result);

}

}

Docs at - https://fortjs.net/docs/concepts/file

--

--

Ujjwal Gupta
Ujjwal Gupta

Written by Ujjwal Gupta

Building starscolab | Ex - Frontend lead Polygon | Creator of jsstore, fortjs | opensource creator | we3, blockchain, solidity | javascript

No responses yet