New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fastify-file-interceptor

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-file-interceptor - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

2

dist/index.d.ts

@@ -7,1 +7,3 @@ export { FileFastifyInterceptor } from "./multer/interceptor/file-fastify-interceptor";

export { diskStorage, memoryStorage } from "multer";
export { contentParser } from "fastify-multer";
export { MulterFile } from "./multer/interface/fastify-multer-interface";

4

dist/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.memoryStorage = exports.diskStorage = exports.FastifyMulterModule = exports.FileFieldsFastifyInterceptor = exports.AnyFilesFastifyInterceptor = exports.FilesFastifyInterceptor = exports.FileFastifyInterceptor = void 0;
exports.contentParser = exports.memoryStorage = exports.diskStorage = exports.FastifyMulterModule = exports.FileFieldsFastifyInterceptor = exports.AnyFilesFastifyInterceptor = exports.FilesFastifyInterceptor = exports.FileFastifyInterceptor = void 0;
var file_fastify_interceptor_1 = require("./multer/interceptor/file-fastify-interceptor");

@@ -17,2 +17,4 @@ Object.defineProperty(exports, "FileFastifyInterceptor", { enumerable: true, get: function () { return file_fastify_interceptor_1.FileFastifyInterceptor; } });

Object.defineProperty(exports, "memoryStorage", { enumerable: true, get: function () { return multer_1.memoryStorage; } });
var fastify_multer_1 = require("fastify-multer");
Object.defineProperty(exports, "contentParser", { enumerable: true, get: function () { return fastify_multer_1.contentParser; } });
//# sourceMappingURL=index.js.map
import { NestInterceptor, Type } from "@nestjs/common";
import { Options } from "multer";
export declare function FilesFastifyInterceptor(fieldName: string, maxCount: number, localOptions?: Options): Type<NestInterceptor>;
export declare function FilesFastifyInterceptor(fieldName: string, maxCount?: number, localOptions?: Options): Type<NestInterceptor>;
/// <reference types="multer" />
export interface FastifyMulterFile extends Express.Multer.File {
export interface MulterFile extends Express.Multer.File {
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.randomStringGenerator = void 0;
const uuid_1 = require("uuid");
const randomStringGenerator = () => uuid_1.v4();
const nanoid_1 = require("nanoid");
const randomStringGenerator = () => nanoid_1.nanoid();
exports.randomStringGenerator = randomStringGenerator;
//# sourceMappingURL=random-generator.js.map

@@ -7,1 +7,3 @@ export { FileFastifyInterceptor } from "./multer/interceptor/file-fastify-interceptor";

export { diskStorage, memoryStorage } from "multer";
export { contentParser } from "fastify-multer";
export { MulterFile } from "./multer/interface/fastify-multer-interface";

@@ -19,3 +19,3 @@ import {

fieldName: string,
maxCount: number,
maxCount?: number,
localOptions?: Options

@@ -22,0 +22,0 @@ ): Type<NestInterceptor> {

@@ -1,1 +0,1 @@

export interface FastifyMulterFile extends Express.Multer.File {}
export interface MulterFile extends Express.Multer.File {}

@@ -1,3 +0,3 @@

import { v4 as uuid } from "uuid";
import { nanoid } from "nanoid";
export const randomStringGenerator = () => uuid();
export const randomStringGenerator = () => nanoid();
{
"name": "fastify-file-interceptor",
"version": "1.0.5",
"version": "1.0.6",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"description": "This library for Nestjs using FastifyAdapter it rely on library fastify-multer and express multer",
"description": "This library for Nest.js using FastifyAdapter it rely on library fastify-multer and express multer",
"author": {

@@ -18,5 +18,5 @@ "name": "Rom",

"@nestjs/common": "^7.6.15",
"@nestjs/core": "^8.0.2",
"@types/multer": "^1.4.5",
"@types/node": "^15.0.1",
"@types/uuid": "^8.3.0",
"fastify": "^3.15.1",

@@ -26,4 +26,3 @@ "reflect-metadata": "^0.1.13",

"rxjs": "^7.0.0",
"typescript": "^4.2.4",
"uuid": "^8.3.2"
"typescript": "^4.2.4"
},

@@ -34,6 +33,4 @@ "keywords": [

"interceptor",
"upload",
"upload file",
"fastify file interceptor",
"form",
"post",
"multipart",

@@ -43,12 +40,13 @@ "form-data",

"fastify",
"middleware"
"@nestjs/platform-fastify"
],
"dependencies": {
"fastify-multer": "^2.0.2",
"multer": "^1.4.2",
"tslib": "^2.2.0"
"fastify-multer": "2.0.2",
"multer": "1.4.2",
"nanoid": "^3.1.25",
"tslib": "2.2.0"
},
"peerDependencies": {
"fastify-multer": "2.0.2",
"multer": "1.4.2",
"fastify-multer": "2.0.2",
"tslib": "2.2.0"

@@ -55,0 +53,0 @@ },

@@ -10,20 +10,24 @@ **Installation**

> main.ts
```javascript
import { contentParser } from 'fastify-multer';
import 'reflect-metadata';
import { FastifyAdapter,NestFastifyApplication } from '@nestjs/platform-fastify';
import { join } from "path"
/* main.ts */
import "reflect-metadata";
import {
FastifyAdapter,
NestFastifyApplication,
} from "@nestjs/platform-fastify";
import { join } from "path";
// update you can import from "fastify-file-interceptor"
import { contentParser, MulterFile } from "fastify-file-interceptor";
async function bootstrap(): Promise<void> {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter()
);
const app =
(await NestFactory.create) <
NestFastifyApplication >
(AppModule, new FastifyAdapter());
await app.listen(3000);
//add this line
app.register(contentParser); yarn add fastify-multer
app.useStaticAsset({root: join(__dirname,"../../example")}) yarn add fastify-static
app.register(contentParser);
/* yarn add fastify-static */
app.useStaticAsset({ root: join(__dirname, "../../example") });
}

@@ -33,5 +37,4 @@ bootstrap();

> app.controller.ts
```typescript
/* app.controller.ts */
import {

@@ -66,2 +69,3 @@ Body,

// Single File
@ApiConsumes("multipart/form-data")

@@ -78,6 +82,3 @@ @Post("single-file")

)
single(
@UploadedFile() file: Express.Multer.File,
@Body() body: SingleFileDto
) {
single(@UploadedFile() file: MulterFile, @Body() body: SingleFileDto) {
console.log({ ...body, photo_url: file });

@@ -87,2 +88,3 @@ return { ...body, photo_url: file };

// Multiple File
@ApiConsumes("multipart/form-data")

@@ -100,3 +102,3 @@ @Post("multiple-file")

multiple(
@UploadedFiles() files: Express.Multer.File[],
@UploadedFiles() files: MulterFile[],
@Body() body: MultipleFileDto

@@ -108,2 +110,3 @@ ) {

// Any File
@ApiConsumes("multipart/form-data")

@@ -120,6 +123,3 @@ @Post("any-file")

)
anyFile(
@UploadedFiles() files: Express.Multer.File,
@Body() body: AnyFileDto
) {
anyFile(@UploadedFiles() files: MulterFile, @Body() body: AnyFileDto) {
console.log({ ...body, photo_url: files });

@@ -129,2 +129,3 @@ return { ...body, photo_url: files };

// File Field
@ApiConsumes("multipart/form-data")

@@ -160,7 +161,5 @@ @Post("fields-file")

**NOTE property destination inside distStorage is the location in our project directory where we want to store the image**
**NOTE property destination inside diskStorage is the location in our project directory where we want to store the image**
</br>
> -Why we using FastifyAdatper then define interface Request from "express" instead interface FastifyRequest from "fastify" ? because function fileFiler and filename inside diskStorage use Request interface Express
> file-upload-util.ts

@@ -172,7 +171,3 @@

export const editFileName = (
req: Request,
file: Express.Multer.File,
callback
) => {
export const editFileName = (req: Request, file: MulterFile, callback) => {
const name = file.originalname.split(".")[0];

@@ -183,7 +178,3 @@ const fileExtName = extname(file.originalname);

export const imageFileFilter = (
req: Request,
file: Express.Multer.File,
callback
) => {
export const imageFileFilter = (req: Request, file: MulterFile, callback) => {
if (!file.originalname.match(/\.(jpg|jpeg|png|gif)$/)) {

@@ -196,8 +187,7 @@ return callback(new Error("Only image files are allowed!"), false);

**If you want to create as CDN from for image and display in browser look at this**
**This page we use interface FastifyRequest instead of interface Request Express because out application use FastifyAdapter and request object is fastify not express**
**Hint**
save image as CDN and display in browser
> file-mapper.ts
```javascript
```typescript
/* file-mapper.ts */
import { FastifyRequest } from "fastify";

@@ -238,4 +228,7 @@

if you already know how to use function from "@nestjs/platform-express" it's the same.
```typescript
"fastify-file-interceptor";
import {

@@ -250,7 +243,4 @@ AnyFilesFastifyInterceptor,

```typescript
"fastify-file-interceptor" using same as "@nestjs/platform-express" a little different with some interface more document on Nest official page
```
"@nestjs/platform-express";
```typescript
"@nestjs/platform-express";
import {

@@ -264,4 +254,3 @@ AnyFilesInterceptor,

**you can install example test on swagger**
**Example** <a href="https://github.com/chanphiromsok/example-fastify-file-interceptor">https://github.com/chanphiromsok/example-fastify-file-interceptor</a>
**I hope creator NestJs add this feature to "@nestjs/platform-fastify"**
You can install example test on swagger
Example Repo on github: <a href="https://github.com/chanphiromsok/example-fastify-file-interceptor">https://github.com/chanphiromsok/example-fastify-file-interceptor</a>

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc