An open API service indexing awesome lists of open source software.

https://github.com/johnufo/app-file-upload-download

This project is a Spring Boot-based application for uploading and downloading files. It supports storing files in both a database (PostgreSQL) and the local file system.
https://github.com/johnufo/app-file-upload-download

jpa multipart-file postgresql spring

Last synced: 3 months ago
JSON representation

This project is a Spring Boot-based application for uploading and downloading files. It supports storing files in both a database (PostgreSQL) and the local file system.

Awesome Lists containing this project

README

        

# File Upload and Download Application

This project is a Spring Boot-based application for uploading and downloading files. It supports storing files in both a database (PostgreSQL) and the local file system.

## Features
- Upload files to a database
- Upload files to the system (local storage)
- Retrieve files from the database
- Retrieve files from the system

## Technologies Used
- **Spring Boot**
- **Spring Data JPA**
- **PostgreSQL**
- **Jakarta Persistence (JPA)**
- **Multipart File Handling**

## Project Structure
```
app-file-upload-download/
├── src/main/java/uz/muydinovs/appfileuploaddownload
│ ├── controller/
│ │ ├── AttachmentController.java
│ ├── entity/
│ │ ├── Attachment.java
│ │ ├── AttachmentContent.java
│ ├── repository/
│ │ ├── AttachmentRepository.java
│ │ ├── AttachmentContentRepository.java
├── src/main/resources/
│ ├── application.properties
```

## Installation & Setup
### Prerequisites
- **Java 17+**
- **PostgreSQL**
- **Maven**

### Steps
1. Clone the repository:
```sh
git clone https://github.com/JohnUfo/app-file-upload-download.git
cd app-file-upload-download
```

2. Configure PostgreSQL Database:
- Update `application.properties` with your PostgreSQL credentials:
```properties
spring.datasource.url=jdbc:postgresql://localhost:5432/app_file
spring.datasource.username=postgres
spring.datasource.password=2373
spring.jpa.hibernate.ddl-auto=update
```

3. Build and Run the Application:
```sh
mvn spring-boot:run
```

## API Endpoints
### Upload File
#### To Database:
```http
POST /attachment/uploadDb
```
- **Request:** Multipart File
- **Response:** `Successfully saved! ID: {id}`

#### To System:
```http
POST /attachment/uploadSystem
```
- **Request:** Multipart File
- **Response:** `Successfully saved! ID: {id}`

### Retrieve File
#### From Database:
```http
GET /attachment/getFileFromDb/{id}
```
- **Response:** File as a downloadable attachment

#### From System:
```http
GET /attachment/getFileFromSystem/{id}
```
- **Response:** File as a downloadable attachment

## Notes
- The uploaded files in the system are saved in the `downloads` folder.
- Ensure PostgreSQL is running before starting the application.