Code Monkey home page Code Monkey logo

ieti-lab10's Introduction

2.4 MongoDB Files API

Create Spring Boot API that allows uploading and serving files.

Part 1: Implement a File uploader API

  1. Clone this project and change the Database configuration with your own connection string in the following file:

Done

  1. Run the project.

  2. Go to your database and verify that the file was created under a fs.files and fs.chunks documents.

  1. Verify that the getFileByName endpoint works and it does returns the lion.jpeg file created on step 2 when requested by name.

  1. Implement the handleFileUpload method. Make sure you return the static url to access the uploaded file by using the getFileByName endpoint.

       //Stores the file into MongoDB
        gridFsTemplate.store(file.getInputStream(), fileName, file.getContentType());

Part 2: Integrate file uploader with React JS project

Done

Part 3: Upgrade your Todo to accept files

I couldn't do it, the previous version of the front uses Jwt to authenticate, this version of the back doesn't use that, additionally it completely changes the structure of the project and I didn't have time this week to implement everything again

  1. Inject the TodoRepository into the RESTController using @Autowired annotation.

  2. Implement the createTodo and getTodoList methods of the RESTController.

  3. Modify the handleSubmit method so it does call the API to create the Todo entry on the server and database:

    • Make asynchronous calls to upload file to the server
    • Once the file upload promise is fulfilled, then save the Todo entry using the POST method of the API.
    • Remember to save the this context into a variable to use it into the nested scopes!
  4. Modify the Todo component on your React project so that it displays the Todo image:

          <td>{this.props.fileUrl ? <img src={this.props.fileUrl} /> : <div/>}</td>
  5. If you have not done it yet, implement and call the method to load the Todo list from the server:

         loadDataFromServer() {
        
                let that = this;
        
                this.axios.get("todo").then(function (response) {
                    console.log("This is my todolist:  ", response.data);
                    that.setState({items: response.data})
                })
                    .catch(function (error) {
                        console.log(error);
                    });
            }
    1. Implement the logic for the following scenario: if the file is not an image but a pdf file, then a file icon appears on the Todo component. When the file icon is clicked then the user gets redirected to the download page.
  6. Verify that the project works as expected.

ieti-lab10's People

Contributors

jualme avatar sancarbar avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.