With two web servers serving the same Django application with the same underlying database, I could now balance all requests between the two servers.
Sessions are stored in the DB. Static media can be handled the same as if I used a content-delivery network (CDN).
But how do I handle user-uploaded media files that sit on a local filesystem of the webserver that receives the upload POST?
Obviously, the second server will miss these files.
What is a reliable solution? NFS to some third server? Constantly running Unison or using a DVCS like Mercurial oder git?
Static media can be handled the same as if I used a content-delivery
network (CDN).
There is your answer. Upload user media to a CDN. Checkout out django-storages for an S3 or Cloudfiles storage backend.
I personally use NFS to a third server, which then serves directly all the media when requested. This reduce the NFS usage to the upload phase, and the media server can be optimized for static assets.
Related
I have two app servers 10.22.33.54 and 10.22.33.56 and I am trying to integrate media on another server IP 10.22.30.40 I created a media directory so what are the method I can use in Django to manage media files?
I have set up an S3 bucket on AWS where I upload my sensitive ‘media’ files from my Django DRF + React app. The files are not public. I use boto3 and Django-storages for that and the upload process works fine. I can also download the files for report generation from backend to return PDF response.
I would now like to display those files one by one from frontend. It seems like I now have two options:
Create a route in Django API/urls to handle media requests and point the app to the media directory. This way, the AWS login is handled by the backend server. This seems to beat the point of using a CDN as all media requests would go via the backend server?
Incorporate login credentials to React front end. This seems insecure.
What would be the recommended way to achieve this? I can’t seem to find the required information.
Thank you.
I have a Moodle website and an Opencart website, I want to share Opencart session data with the Moodle website.
How would I do this?
See if you're going to use session for two different websites and I am assuming these both websites are deployed on different servers then do checkout Redis for the same. You can go through this article on Redis Session Management. It is better than Database or File storage and you can scale up easily in case of large traffics.
I have a decoupled applications build with Django 2, an API with DRF and an Angular 6 frontend application. I want to enable users to upload photos for their profiles, and probably in the future some pdfs, and after some research I figured out that the most convenient thing to do would be to store these files in an Amazon S3 bucket.
I have found numerous resources about how to upload files to an S3 bucket on both, Angular and Django, and now I was wondering what would be the best approach to do this in my decoupled application: should I manage it on the frontend and not use my backend at all? or should I pass the file from my angular to my Django app and then upload it to the bucket from there?
Some pros and cons of both approaches? It's my first time doing this and I haven't been able to find many resources for decoupled applications.
Any help is welcome! thanks!
The best practice
Anything related to data must be managed by your backend i.e Django, Angular is just a client.
You should pass the file from angular to Django app and then upload it
to the s3 bucket from there
Cons using client
Suppose in future, if you will develop mobile apps to consume your rest APIs then you need to rewrite the whole management there also.
You have to keep your s3 bucket API keys on the client and it is easily accessible to hackers.
dist folder size will be going to increase that will affect the load time of your site
If you are uploading files from client to S3 bucket, it will use the user's internet and in most of the cases it is slower than your sever's internet
I have certain documents that I want to limit access to through Django to authorized users with permissions only.
If I'm going to use Django as a proxy to serve static files in a view, what are the implications? I'm used to serving static files in Apache and configuring that my media is served without any handlers, but what happens if someone starts downloading 500mb through my Django proxy? Will my Django thread be locked for that user until he recieves the 500mb response?
See the answers to this question to learn how to tell the web server to handle serving the file.
You could use apache auth from django.contrib.auth.handlers.modpython for the permission handling.