---
title: "How to upload an image with other data in NestJS, please help?"  
description: "How to upload an image with other data in NestJS, please help?"  
author: "Utpal Vishwas"  
published: 2023-07-31  
updated: 2023-08-01  
canonical: https://www.mindstick.com/forum/159381/how-to-upload-an-image-with-other-data-in-nestjs-please-help  
category: "javascript"  
tags: ["javascript", "nest js"]  
reading_time: 2 minutes  

---

# How to upload an image with other data in NestJS, please help?

How to [upload](https://www.mindstick.com/forum/12860/how-to-upload-file-asynchronously-using-generic-handler) an [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) with other [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) in NestJS, please help?

## Replies

### Reply by Aryan Kumar

Sure, here is how to upload an image with other data in NestJS:

```plaintext
import { Controller, Injectable, UploadedFile } from '@nestjs/common';
import { FileService } from './file.service';

@Controller('upload')
export class UploadController {
  constructor(private readonly fileService: FileService) {}

  @Post()
  async uploadImage(
    @UploadedFile() file: File,
    otherData: { name: string },
  ) {
    const fileName = await this.fileService.saveFile(file);
    return { fileName, otherData };
  }
}
```

The `UploadController` class will have a `@Post()` method that will handle the file upload. The method will accept two parameters:

- The `file` parameter will be an instance of the `UploadedFile` class. The `UploadedFile` class represents a file that has been uploaded to the server.
- The `otherData` parameter will be an object that contains other data that needs to be saved.

The `@Post()` method will first save the file to the file system using the `fileService` service. Then, the method will return an object that contains the file name and the other data.

The `fileService` service is a service that provides methods for saving files to the file system. The `saveFile()` method of the `fileService` service will save the file to the file system and return the file name.


---

Original Source: https://www.mindstick.com/forum/159381/how-to-upload-an-image-with-other-data-in-nestjs-please-help

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
