Giter Site home page Giter Site logo

image-hosting-api's Introduction

Image hosting api

Project Requirements

  1. Skip the registration part, assume users are created via the admin panel.
  2. Users should be able to do the following: a. Upload images via HTTP request b. List their images
  3. There are three account tiers โ€“ Basic, Premium and Enterprise. a. Users that have a "Basic" plan after uploading an image get: i. A link to a thumbnail that's 200px in height b. Users that have a "Premium" plan get: i. A link to a thumbnail that's 200px in height ii. A link to a thumbnail that's 400px in height iii. A link to the originally uploaded image c. Users that have an "Enterprise" plan get: i. A link to a thumbnail that's 200px in height ii. A link to a thumbnail that's 400px in height iii. A link to the originally uploaded image iv. Ability to fetch a link that expires after a number of seconds (user can specify any number between 300 and 30000)
  4. Admins should be able to create arbitrary plans with the following configurable attributes: a. Thumbnail sizes b. Presence of the link to the originally uploaded file c. Ability to generate expiring links
  5. Admin UI should be done via django-admin
  6. There should be NO custom user UI (just browsable API from DRF)
  7. Please keep the following in mind: a. Python 3.6 or above should be supported b. Ease of running the project (use of docker-compose is a plus) c. Tests d. Validation e. Performance considerations (assume there can be a lot of images and the API is frequently accessed)

Development/Testing

Assuming a linux dev environment: docker, docker-compose, make packages are needed to be installed before running any of the rest of commands for the development environment.

All operations to run/execute the project are in the makefile. Running:

# this will give help for all the subcommands
make

# build local development docker image
make setup
# run db and apply migrations
make database

# run tests
make test 

# add super user for admin site, generate static files for django admin etc. and run dev server.
make createsuperuser static-files run-server

Users/Plans have to be created in the django-admin UI and each user needs to be assigned a plan. There are 3 predefined plans (Basic, Premium, Enterprise)

Visit: http://localhost:8000/admin (credentials admin:123)

After creating a user with a plan in order to get a token

curl --request POST \
  --url http://localhost:8000/api/token/ \
  --header 'Content-Type: application/json' \
  --data '{
	"username": "user1",
	"password": "password"
}'

# {
# 	"token": "ef6847c05d873734f9d9cdf3fbd02f571e23e6ba"
# }

To upload an image:

curl --request POST \
  --url 'http://localhost:8000/api/images/' \
  --header 'Authorization: Token <token-from-previous-request>' \
  --header 'Content-Type: multipart/form-data' \
  --form name=last \
  --form image_field=@/path/to/image/file

To list all images uploaded from user:

curl --request GET \
  --url 'http://localhost:8000/api/images/' \
  --header 'Authorization: Token <token-from-previous-request>'

To get the image back with one of links returned in the above response:

curl --request GET \
  --url http://localhost:8000/api/images/links/b7db14c4-71d1-48ac-9d13-c1e91389023d

image-hosting-api's People

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.