Giter VIP home page Giter VIP logo

gpds's Introduction

GPDS version 0.4.1

Simple GET-PUT-DELETE service (GPDS) to (temporary) store your files as an alternative to NFS shared folders.

It uses Gunicorn WSGI server as base and pass through all it's options. So you can simply start it using next command gpds WORKING-DIRECTORY, where working directory is path to store and read files (by default, it'll be started on 8000 port).

This server can process only three request types, so try them with curl from your console:

curl -i -X PUT -T somefile.jpg http://localhost:8000/

HTTP/1.1 201 Created
Server: gpds/0.3.1
Date: Mon, 04 Feb 2013 16:06:27 GMT
Connection: close
Location: /55/1c/551ced9e9d54658155ae8b4197afd32087a1c551.jpg
Content-Length: 0

So, what can we see here. GPDS created new file on yours file system (201 Created HTTP response) and this file is accessible on next address http://localhost:8000/55/1c/551ced9e9d54658155ae8b4197afd32087a1c551.jpg. This big string 551...551 is SHA1 hash from uploaded file content. So we can do next trick:

curl -i -X PUT -T somefile.txt http://localhost:8000/

HTTP/1.1 200 OK
Server: gpds/0.3.1
Date: Mon, 04 Feb 2013 16:17:12 GMT
Connection: close
Location: /55/1c/551ced9e9d54658155ae8b4197afd32087a1c551.jpg
Content-Length: 0

As you can see, Location is the same as in previous request. GPDS won't rewrite uploaded file.

OK, let's try to access this file:

curl -i http://localhost:8000/55/1c/551ced9e9d54658155ae8b4197afd32087a1c551.jpg

HTTP/1.1 200 OK
Server: gpds/0.3.1
Date: Mon, 04 Feb 2013 16:38:26 GMT
Connection: close
Content-Length: 56737
Content-Type: image/jpeg

...file content...

Cool, our service sent our image for us properly. Now we'll delete this file and try to access it one more time:

curl -i -X DELETE http://localhost:8000/55/1c/551ced9e9d54658155ae8b4197afd32087a1c551.jpg

HTTP/1.1 204 No Content
Server: gpds/0.3.1
Date: Mon, 04 Feb 2013 16:40:49 GMT
Connection: close
Content-Length: 0

curl -i http://localhost:8001/55/1c/551ced9e9d54658155ae8b4197afd32087a1c551.jpg

HTTP/1.1 404 Not Found
Server: gpds/0.3.1
Date: Mon, 04 Feb 2013 16:41:09 GMT
Connection: close
Content-Length: 0

As you can see GPDS successfully erased your file from disk and next time sent not found response for you.

Ok, now we'll try to do previous work with Python:

from requests import put, get, delete

filename = 'somefile.jpg'
server = 'http://localhost:8000'
r = put('%s/%s' % (server, filename), data=open(filename, 'rb'))
result = ''.join([server, r.headers['Location']])
print result # http://localhost:8000/2c/f3/2cf3af58d2416d40e18ca5e38f5baabc8a092765.jpg

r = get(result)
print r.headers['Content-Type'] # image/jpeg (our image sent for us)

for _ in range(2):
    r = delete(result)
    print r.status_code # 1st time - 204 (No Content = deleted),
                        # 2nd time - 404 (Not Found = already deleted)

As you can see, we used requests library, best way to do HTTP request in Python.

gpds's People

Contributors

rembish avatar tomasflam avatar

Watchers

Vitezslav Lindovsky avatar James Cloos avatar  avatar Filip Šubr avatar Roman avatar Elias Ondrej avatar  avatar Glogster Machine 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.