Skip to content

Commit

Permalink
[Storage] Remove @foal/formidable
Browse files Browse the repository at this point in the history
  • Loading branch information
LoicPoullain committed Aug 27, 2020
1 parent 42ec80b commit 7b58026
Show file tree
Hide file tree
Showing 14 changed files with 0 additions and 2,873 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ jobs:
run: cd packages/ejs && npm run test
- name: Run unit tests of @foal/examples
run: cd packages/examples && npm run test
- name: Run unit tests of @foal/formidable
run: cd packages/formidable && npm run test
- name: Run unit tests of @foal/graphql
run: cd packages/graphql && npm run test
- name: Run unit tests of @foal/jwks-rsa
Expand Down
50 changes: 0 additions & 50 deletions docs/file-system/upload-and-download-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,53 +422,3 @@ class AppController {
| file | string | Name of the file with its extension (e.g. `report.pdf`). If the string provided is a path (e.g. `downloaded/report.pdf`), then Foal will automatically extract the filename (i.e. `report.pdf`). |
| forceDownload (optional) | boolean | It indicates whether the response should include the `Content-Disposition: attachment` header. If this is the case, browsers will not attempt to display the returned file (e.g. with the browser's PDF viewer) and will download the file directly. |
| filename (optional) | string | Default name proposed by the browser when saving the file. If it is not specified, FoalTS extracts the name from the `file` option.

### The `@foal/formidable` package

> *Deprecated since v1.7. Use the `@ValidateMultipartFormDataBody` hook instead.*
> **Warning:** This package only allows you to upload files to your local file system. It does not work with Cloud storage.
You can upload files to your local file system using the library [formidable](https://www.npmjs.com/package/formidable). It will automatically parse the incoming form and save the submitted file(s) in the directory of your choice. A random id is generated for each saved file.

```sh
npm install formidable @types/formidable
npm install @foal/formidable
```

> The package `@foal/formidable` is a small package that allows you to use `formidable` with promises. It only has one function: `parseForm`.
Assuming that the client submits a form with a field named `file1` containing a file, you can save this file using `IncomingForm` and `parseForm`.

```typescript
import { Context, HttpResponseOK, Post } from '@foal/core';
import { parseForm } from '@foal/formidable';
import { IncomingForm } from 'formidable';

export class AppController {

@Post('/upload')
async upload(ctx: Context) {
const form = new IncomingForm();
form.uploadDir = 'uploaded';
form.keepExtensions = true;
const { fields, files } = await parseForm(form, ctx);

console.log(files.file1);
// {
// "size": 14911887,
// "path": "uploaded/upload_de9cb95c.pdf",
// "name": "example.pdf",
// "type": "application/pdf",
// "mtime": "2019-03-25T13:58:27.988Z"
// }

return new HttpResponseOK(
'The file has correctly been uploaded. '
+ 'You can find it on the server at '
+ files.file1.path
);
}

}
```
1 change: 0 additions & 1 deletion packages/acceptance-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"dependencies": {
"@foal/core": "^1.11.0",
"@foal/csrf": "^1.11.0",
"@foal/formidable": "^1.11.0",
"@foal/jwks-rsa": "^1.11.0",
"@foal/jwt": "^1.11.0",
"@foal/mongodb": "^1.11.0",
Expand Down
85 changes: 0 additions & 85 deletions packages/acceptance-tests/src/upload-and-download.spec.ts

This file was deleted.

142 changes: 0 additions & 142 deletions packages/acceptance-tests/src/upload-and-download.typeorm.spec.ts

This file was deleted.

21 changes: 0 additions & 21 deletions packages/formidable/LICENSE

This file was deleted.

67 changes: 0 additions & 67 deletions packages/formidable/README.md

This file was deleted.

Loading

0 comments on commit 7b58026

Please sign in to comment.