https://github.com/dfm18/spring-boot-firebase-upload
A demonstration of how to upload files to Firebase Storage using Spring Boot.
https://github.com/dfm18/spring-boot-firebase-upload
cloud firebase firebase-storage java junit maven spring spring-boot upload-file
Last synced: 4 months ago
JSON representation
A demonstration of how to upload files to Firebase Storage using Spring Boot.
- Host: GitHub
- URL: https://github.com/dfm18/spring-boot-firebase-upload
- Owner: dfm18
- Created: 2024-07-24T00:59:26.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-07-24T00:59:29.000Z (11 months ago)
- Last Synced: 2025-01-09T10:38:29.563Z (6 months ago)
- Topics: cloud, firebase, firebase-storage, java, junit, maven, spring, spring-boot, upload-file
- Language: Java
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Spring Boot Firebase Upload
[](https://www.java.com/es/)
[](https://maven.apache.org/)
[](https://spring.io/)
[](https://spring.io/projects/spring-boot)
[](https://junit.org/junit5/)
[](https://firebase.google.com)This project is a demonstration of how to upload files to Firebase Storage using Spring Boot.
## Requirements
- Java 21
- Maven
- Firebase account with access to Firebase Storage and a JSON credentials file## Configuration
1. **Configure Firebase**
Make sure you have a project in Firebase and download the JSON credentials file. This file is used to authenticate the application with Firebase.
2. **Set up environment variables**
We use environment variables to configure access to Firebase. Create a `.env` file in the root directory of the project based on the example file `.env.example`:
```env
FIREBASE_CREDENTIALS_PATH=/path/to/your/firebase/credentials.json
FIREBASE_STORAGE_BUCKET_NAME=your-firebase-storage-bucket
```Replace `/path/to/your/firebase/credentials.json` with the path to the JSON credentials file and `your-firebase-storage-bucket` with the name of your Firebase Storage bucket.
3. **Configure the `application.properties` file**
The `src/main/resources/application.properties` file should contain:
```conf
spring.application.name=spring-firebase-uploadfirebase.credentials-path=${FIREBASE_CREDENTIALS_PATH}
firebase.storage.bucket-name=${FIREBASE_STORAGE_BUCKET_NAME}
```## Running the application
1. **Load the environment variables**
Make sure the environment variables are set. In IntelliJ IDEA, you can add the variables from the `.env` file to the environment variables in the run configurations:
- Open the "Run/Debug Configurations" dialog.
- Select your run configuration.
- In the "Environment Variables" field, click the folder button.
- Choose the `.env` file in the file chooser.
- Save the changes.You can find the Jetbrains Official Tutorial [here](https://www.jetbrains.com/help/objc/add-environment-variables-and-program-arguments.html#add-environment-variables).
2. **Run the application**
```bash
mvn spring-boot:run
```The application will be available at `http://localhost:8080`.
## Endpoints
- **POST `/upload`**
This endpoint allows you to upload files to Firebase Storage. You can send files using the file parameter in the request.
Example usage with curl:
```bash
curl -F "file=@/path/to/your/file.txt" http://localhost:8080/upload
```It will return the public link of the uploaded file.
## Tests
Tests are set up to verify the upload, retrieval, and deletion of files in Firebase Storage. To run the tests, use the following command:
```bash
mvn test
```