Frage

I am trying to create facebook group like web-page where people can post any text or image on the group page and all the users subscribed to that page would get real time feed of the text and images that people post.

To achieve this I am using django + tornado integration where the web-page is rendered by django and all the asynchronous requests are handled by tornado using websockets.

So, On the group page, I was able to implement transfer of text from client to server using websockets and all the users get real time update of the new text posted on the page. Now, I would like to allow people to share images as well.

I am not sure if I should use django(upload using POST) or tornado(using websockets) to upload the images . What is the preferred way in such scenarios ?

War es hilfreich?

Lösung

Proposal: User Uploads the image to django, django stores it whenever and return url to it. The user then sends this url over the websocket, similar to text post.

Andere Tipps

You should use Django for image upload, it is pretty efficient in doing so. Here is a simple model for image upload.

from django.db import models

LEFT = "left"
RIGHT = "right"
FLOAT_CHOICES = ((LEFT, _("left")),
            (RIGHT, _("right")),
)

class Sample(CMSPlugin):

    float = models.CharField(_("Image placement"), max_length=10, blank=True, null=True,
        choices=FLOAT_CHOICES, help_text=_("Move image left, right or center."))
    image = models.ImageField(_("image"), upload_to=CMSPlugin.get_media_path)
    big_header  = models.TextField(_("Quotation"),null=True, max_length=150)
    name = models.CharField(_("Name of Recommending person"), max_length=150)
    detail = models.CharField(_("School detail"), max_length=200)

In combination with these include two packages in your requirements.txt file:

 boto==2.7.0
 django-storages==1.1.6

These libraries provides very nice support for uploading images to S3(which is what everyone prefer for media files). Once your image is uploaded successfully, it returns an image path which is in turn saved into your database.

In order to use S3, add these settings in your settings.py or base.py.

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'

AWS_STORAGE_BUCKET_NAME = '<s3-bucket-name>'
AWS_S3_SECURE_URLS = False
AWS_PRELOAD_METADATA = True
AWS_ACCESS_KEY_ID = os.environ['AWS_ACCESS_KEY_ID']
AWS_SECRET_ACCESS_KEY = os.environ['AWS_SECRET_ACCESS_KEY']
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top