Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added Docs for file-upload #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions docs/File-upload/File-upload.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
Title: File Upload
sidebar_label: File Upload
---

<head>
<title>File Upload</title>
</head>
<p>


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove excessive blank lines and ensure proper structure around headings.

There are multiple places with consecutive blank lines that should be reduced to a single blank line to comply with markdown best practices. Additionally, headings should be surrounded by blank lines to improve readability.

Also applies to: 12-12, 31-31, 34-34

Tools
Markdownlint

11-11: Expected: 1; Actual: 2
Multiple consecutive blank lines

(MD012, no-multiple-blanks)


## Introduction
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure headings are surrounded by blank lines for better readability.

Adding blank lines around headings will improve document structure and readability, aligning with markdown best practices.

Also applies to: 18-18, 25-25, 35-35

Tools
Markdownlint

13-13: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines

(MD022, blanks-around-headings)

The Stencil File Upload module provides a robust and configurable solution for handling file uploads within your application. Built on top of the `multer` middleware for Express, it facilitates the handling of data posted in the `multipart/form-data` format, which is predominantly used for file uploads via HTTP `POST` requests. This module's flexibility allows you to tailor its behavior to suit your specific application requirements.

## Features

### File Upload
The Stencil File Upload module supports both single and multiple file uploads, offering a seamless experience for attaching files through an API `POST` request. Key features include:

- **Multiple File Uploads:** Stencil File upload module supports one or more files in a single request.
- **Storage Options:** Files can be stored in local storage or in a MinIO database, providing flexibility in how you manage and access uploaded files.
- **Configurable Middleware:** Built on `multer`, the module can be adjusted to meet various needs, such as file size limits, file type restrictions, and more.

### File Download
In addition to handling uploads, the Stencil File Upload module includes a comprehensive file download service. This feature ensures that users can reliably retrieve uploaded files as needed. Key features include:

- **Efficient File Retrieval:** Download files with ease.
- **Storage Integration:** Files stored in both local storage and MinIO databases are supported, ensuring that downloads are flexible and accessible regardless of where the files are saved.


**Note:** For additional information on NestJS File Upload, refer to the official NestJS documentation [here](https://docs.nestjs.com/techniques/file-upload)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a reference to NestJS in the appropriate section.

The note about NestJS File Upload seems misplaced under the Stencil File Upload module. Consider moving this note to a more relevant section or clarify why it's mentioned here.



## Development Setup
To get started with the Stencil File Upload module in your project, initialize a new Stencil project with the file upload service using the following commands in your CLI:

```sh
stencil new <project-name> --service-file-upload
# or
stencil new <project-name> -fu
```

This will configure the file upload service in your project, enabling efficient management of file uploads and downloads.

</p>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure the file ends with a newline character.

The file should end with a single newline character to comply with markdown standards.

Committable suggestion was skipped due to low confidence.

Tools
Markdownlint

46-46: null
Files should end with a single newline character

(MD047, single-trailing-newline)

156 changes: 156 additions & 0 deletions docs/File-upload/Setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
---
title: Setting Up File Upload
sidebar_label: File Upload Setup
---

<head>
<title>File Upload Setup</title>
</head>
<p>

If you forgot to initialize `service-file-upload` when creating your new Stencil app, you can still add it using the following command:

```sh
stencil g service-file-upload
# or
stencil g fu
```

This command installs all necessary dependencies for `service-file-upload`.

**Note:** For better safety, execute:
```sh
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surround fenced code blocks with blank lines.

Fenced code blocks should be surrounded by blank lines to separate them visually from other content, which enhances readability.

Also applies to: 49-49, 54-54, 130-130, 132-132, 149-149

Tools
Markdownlint

22-22: null
Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)

npm install
or
yarn install
```

## Setup Dependent Services

This example depends on MinIO as an S3-based storage engine to store the uploaded files. A `docker-compose.yml` file has been provided at the root of this project which sets up a Minio instance for your use. You can start the instance by running:

```bash
docker-compose up -d
```

## Setting up the Environment

Copy the example environment file to create your own `.env` file:

```bash
cp env-example .env
```

## Setting up File Upload Manually

To manually set up the `file-upload` functionality, you need to register the `FileUploadModule` module in your module which can be imported from the `@samagra-x/stencil` package.

**Prerequisites:**
```sh
npm i @samagra-x/stencil
```

For example:
```typescript
// other imports
import { FileUploadModule } from '@samagra-x/stencil';

@Module({
imports: [FileUploadModule],
// other configs
})
export class AppModule {}
```

> Via the [CLI](https://github.com/SamagraX-stencil/stencil-cli)

To set up `file-upload` functionality automatically via the CLI, simply run the following command:

```bash
stencil add service-file-upload
```

## Running the App

```bash
# development
yarn run start
# or
npm run start

# watch mode
yarn run start:dev
# or
npm run start:dev

# production mode
yarn run start:prod
# or
npm run start:prod
```

## Test

```bash
# unit tests
yarn run test
# or
npm run test

# e2e tests
yarn run test:e2e
# or
npm run test:e2e

# test coverage
yarn run test:cov
# or
npm run test:cov
```

## File Upload Instructions

To upload single or multiple files, follow the steps below:

### Endpoint
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure proper structure around headings and lists.

Headings and lists in the document should be surrounded by blank lines to improve readability and comply with markdown standards.

Also applies to: 118-118, 121-121, 128-128, 141-141, 144-144, 147-147

Tools
Markdownlint

115-115: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines

(MD022, blanks-around-headings)

`POST /files/upload-files`

### Query Parameters
- **destination**: Specifies the target directory for the uploaded files. Example: `/files/upload-files?destination=uploads`.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure lists are surrounded by blank lines.

Surrounding lists with blank lines will improve the structure and readability of the document.

Also applies to: 123-123, 134-134, 145-145

Tools
Markdownlint

119-119: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)


### Request Body
The request should include the following form-data fields:
- **file**: The file(s) to be uploaded.
- **filename**: The corresponding filename(s) for the uploaded file(s).

**Note**: Ensure that the number of files and filenames are the same and listed in the correct order.

### Example
To upload files to the `uploads` directory:
```
POST /files/upload-files?destination=uploads
```
In the form-data:
- Add the files under the field name `file`.
- Add the filenames under the field name `filename`.

## File Download Instructions

To download a file, follow the steps below:

### Endpoint
`GET /files/download/:destination`

### Parameters
- **destination**: The relative path to the file within the `uploads` directory. For example, if the file is located at `your_project/uploads/resume`.

### Example
To download a file located at `your_project/uploads/resume`:
```
GET /files/download/resume
```

**Note**: The default base directory for downloads is `/uploads`, located at the root level of your project directory (same level as the `node_modules` directory).

By following these steps, you can efficiently handle file uploads and downloads within your project.
</p>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure the file ends with a newline character.

The file should end with a single newline character to comply with markdown standards.

Committable suggestion was skipped due to low confidence.

Tools
Markdownlint

156-156: null
Files should end with a single newline character

(MD047, single-trailing-newline)

5 changes: 5 additions & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ module.exports = {
collapsed: false,
items: ['monitoring/nestjs-monitor', 'monitoring/setup'],
},
{
type: 'category',
label: 'File-Upload',
items: ['File-upload/File-upload','File-upload/Setup']
},
{
type: 'category',
label: 'CLI',
Expand Down