Giter Site home page Giter Site logo

image-repo's Introduction

image-repo

Author: Mohan Shobana
LinkedIn: https://www.linkedin.com/in/mohan-shobana-018m93/
Contact: [email protected]

INRODUCTION

TASK: Build an image repository.

The task was to create an Image Repository. The challenge has been tackled to provide all the basic features in the form of API endpoints to the users. Also a basic UI has been created (nothing too fancy, just to test the functionality).

HOW-TO-RUN

  1. GITHUB/ GOOGLE OAuth2 Setup
    The application uses GITHUB and GOOGLE OAuth2 for authentication. Hence we need to generate the client-id and client-secret for access the APIs and run the application.
    The Application.properties(https://github.com/SHOBANAM93/image-repo/blob/92d81095c051478cb5ba291cd78380e5a4da7c36/src/main/resources/application.properties) file has the keys where you might need to key in your GITHUB/GOOGLE client-id and client-secret.
    image

  2. PostGreSQL database setup The application uses PostgresSQL as a relational DB to store images and associated information.
    The Application.properties(https://github.com/SHOBANAM93/image-repo/blob/92d81095c051478cb5ba291cd78380e5a4da7c36/src/main/resources/application.properties) file has the keys where you might need to change values as per your POSTGRES setup.
    image

Features Developed

  1. Authentication
  2. Upload Images
  3. Search/Retrieve Images
  4. Encryption

Authentication

With the use of GITHUB and GOOGLE OAuth2, I have enabled the authentication of user. User cannot access APIs without getting authorized.
Once the application is running:
image

You can launch the website by opening the following URL(http://localhost:8080/) in any browser:
image

You can click either the GITHUB or GOOGLE login to authorize the application to use your data and authenticate you to use the application.
GITHUB
image
GOOGLE
image

The authenticated user would re-routed back to the homepage using the redirect-url for the application.
image

Using the logged-in user's principal values we fetch the name
We add the JSESSIONID and XSRF-TOKEN with each API call.
API : /user
image image

Upload Images

The upload API can be used to upload SINGLE image or multiple images as per user's need.
The user's image size limit (max-file-size) is mentioned in the application.properties (https://github.com/SHOBANAM93/image-repo/blob/92d81095c051478cb5ba291cd78380e5a4da7c36/src/main/resources/application.properties). Also altogether all files cannot exceed max-request-size.
Both these properties can be edited as per need.
image

Once that is set, the application is running and user is authenticated, we can click upload button to get the upload images form.
image

  1. Using the browse button, select all images.
  2. Next, we can give space-separated tagnames to the images being uploaded. Using these tags we can later retrieve them.
  3. Finally we can select if these images are for private view only or for public view also.
  4. Click submit.

This invokes the upload API.
API: /upload
Method: HTTP POST
RequestBody: The files, tags and privacy for the images.
JSESSIONID and XSRF-TOKEN are added.
image

Network tab shows request
image
Respose
image

Search/Retrieve Images

There are two APIs which could be used to fetch images. We can fetch images by giving the tags or by giving the exact image name.
The /retrieve/{imageName} API can be used to fetch the exact images matching the imageName.
The /retrieve/tags API can be used to fetch the images using the tag name.

API: /retrieve/{imageName}
Method: HTTP GET
Params: imageName - image name
JSESSIONID and XSRF-TOKEN are added.
UI
image
Request
image Response
{"message":"Image retrieved","imageSet":[{"email":"[email protected]","name":"restart.gif","type":"image/gif","privacy":"public","picByte":"image in bytes","tags":null}]}
image

API: /retrieve/tags
Method: HTTP POST
Request Body: tags (space separated)
JSESSIONID and XSRF-TOKEN are added.
UI
image
Request
image Response
image

Encryption

In the backend I'm compressing the image bytes using java.util.zip.Inflater(https://github.com/SHOBANAM93/image-repo/blob/70d29e4db468162128b6d1b7d4e750dacfc6bbad/src/main/java/com/interview/imageRepository/utils/CompressionUtils.java) and then encrypting the image bytes further by using AES encryption (https://github.com/SHOBANAM93/image-repo/blob/70d29e4db468162128b6d1b7d4e750dacfc6bbad/src/main/java/com/interview/imageRepository/utils/CryptoUtils.java).

And while retrieving them back, I'm first decrypting the image bytes and then decompressing the image before adding it to the response.

DATABASE

Using PostGreSQL as the relational DB to store the images in byte format. The tag table stores the tags associated to the images. There is one-to-many relationship between image and tag table. one image can have many tags associated to it.
Image Table
image
Tag table
image

image-repo's People

Contributors

shobanam93 avatar

Watchers

 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.