How to upload a movie file in Django? - django

I am sorry if this question is already posted somewhere.
I am very new to Django. I have been googling around for quite a long time for sample codes to upload large files using Django, but goes in vain.
Can anyone help me with some sample code for uploading large files in Django or provide relavant reliable link(s)?
Thanks in advance.

Django itself handles large files uploads quite well (the whole file is not loaded to memory since 1.0, see http://code.djangoproject.com/ticket/2070).
But django usually sits behind web server and there is often a limit over request body. So Web server config should be probably adjusted (if you are using apache, look at http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestbody ).

There is this called django-video. I haven't tried it though. I have used django-basic-apps
which can handle video, music and image uploads.

Related

ReactNative, Apollo and Django: upload files

I decided to learn such a technology as GraphQL. For this, I came up with an application (I develop it on ReactNative), a python backend (django-graphene). How the client chose Apollo. I set everything up, everything works, I even did a part already. And here I needed to upload a profile photo. The problem is that I haven't found a way to do this. I used to use the REST API and the client was axios. So I just took the FormData and passed it. Accordingly, the backend accepted and saved as usual. And here I don't even know where to start. I found the apollo-upload-client package, but I didn't find how to integrate it into ReactNative (more precisely, there is a description there, but I didn't understand how to use it correctly). I do it like this:
const fileSubstitute = {
uri: uriFromCameraRoll,
name: "a.jpg",
type: "image/jpeg",
};
I found graphene-file-upload for the backend, it seems to see my files, but I don't know how to save them (by the way, I can transfer the file without apollo-upload-client).
I really like GraphQL, but uploading files is a big deal. If I don't solve it, I will be forced abandon this technology.
P.S. I didn't find any information on how to upload files via GraphQL at all. Maybe it is necessary to work with files in a different way? I will be grateful for any help

Circumvent getImageData using Django

So I want to do pixel manipulation in my Django app, and I want the user to be able to provide links to their own image files. I already saw several solutions, including proxy servers, but I can't seem to get any of them to work, and most of them are specifically for JSON and not images.
The latest one I tried involves using the django corsheaders plugins that adds the cross origin resource sharing headers to responses, but I'm unsure as to what responses exactly are—I'm pretty new to servers.
In any case, this is the error I keep running into:
ImageEditor.js:509 Uncaught SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data.
I'm looking for some way to serve images from other domains onto my website and to manipulate their pixels.
Thanks in advance, and please, explain it as though I was someone who doesn't understand anything about servers. :D

Having problems with Image File POST to Django Server through API

I've spent all day trying to get this Imagefile POST working to no avail. I would be extremely grateful if anyone could provide a little assistance to push me in the right direction! I am using Django Tastypie Restful API service.
Here is what I have so far in my attempt to POST an image to my server and save it - but I think I've gotten the whole spectrum of status errors from 404s to 500s. Would greatly appreciate any insight :) http://pastebin.com/7iXpDvkD
Thank you in advance!
Don't try to post an image in Tastypie JSON format. Upload it using a multi-part form data in plain Django. I am saying so not because you can't do, but coz its difficult and not the right approach also. Secondly it increases the uploaded file-size 30%-40% which might be a problem to most people.
Still I leave it to you decide what to do and I am putting links for file uploading using Django and Tastypie both. Make your choice.
Plain django - https://docs.djangoproject.com/en/dev/topics/http/file-uploads/
This is straight from Django docs and mostly sufficient for any basic needs.
Using Tastypie- Django-tastypie: Any example on file upload in POST?
How do you upload a file with a POST request on django-tastypie?
I figured out the solution to my issue which was a faulty curl command in the file directory.

Need help setting up django-filetransfers

My setup is: Django 1.3/Python 2.7.2/Win Server 2008 R2/IIS 7.5/MS SQL Server 2008 R2. I am developing an application whose main function is to analyze uploaded files and produce a report.
Reading over the documentation for django-filetransfers, I believe this is a solution to a problem I've been trying to solve for a while (i.e. form-based file uploads completely block all Django responses until the file-transfer finishes...horror for even moderate-sized files).
The documentation talks about piping uploads to S3 or Blobstore, and that might be what I end up doing eventually, but during development I thought maybe I could just set up my own "poor-man's S3" on a server that I control. This would basically just be another Django instance (or possibly a simple ASP.NET app) whose sole purpose is to receive uploaded files. This sounds like it should be possible with django-filetransfers and would solve the problem of Django responsiveness (???).
But I am missing some bits of understanding how this works in general, as well as some specifics. Maybe an example will help: let's say I have MyMainDjangoServer and MyFileUploadServer. MyMainDjangoServer will serve the views, including the upload form. MyFileUploadServer will "catch" the uploaded files. My questions/confusion are as follows:
My upload form will contain additional fields beyond just the file(s)...do I understand correctly that MyMainDjangoServer will somehow still get that form data, minus the file data (basically: request.POST), and the file data gets shunted over to MyFileUploadServer? How does this work? Will MyMainDjangoServer still block during the upload to MyFileUploadServer?
I assume that what I would need to do on MyFileUploadServer is have a view/URL that handles the form request and sucks out the request.FILES data. What else needs to happen? What happens to the rest of the form data?
How would I set up my settings.py for this scenario? The django-filetransfers examples seem to assume either S3 or GAE/Blobstore but maybe I am missing some basics.
Any advice/answers appreciated...this is a confusing and frustrating area of Django for me.
"MyMainDjangoServer will somehow still get that form data, minus the file data (basically: request.POST), and the file data gets shunted over to MyFileUploadServer? How does this work? Will MyMainDjangoServer still block during the upload to MyFileUploadServer?"
I know the GAE Blobstore, presumably S3 as well, handles this by requiring you to give it a success_url. In your case that would be the url on MyMainDjangoServer where your file receiving view on MyFileUploadServer would re-post the non-files form data to once the upload is complete.
Have a look at the create_upload_url method here: https://developers.google.com/appengine/docs/python/blobstore/functions
You need to recreate this functionality in some form (see below).
"How would I set up my settings.py for this scenario?"
You'd need to create your own filetransfers backend which would be a file with a prepare_upload function in it.
You can see the App Engine one here:
https://github.com/django-nonrel/djangoappengine/blob/develop/storage.py
The prepare_upload method just wraps the GAE create_upload_url method mentioned above.
So in your settings.py you'd have something like:
PREPARE_UPLOAD_BACKEND = 'myapp.filetransfers_backend.prepare_upload'
(i.e. the import path to your prepare_upload function)
For the rest you can start with the ones provided by filetransfers already:
SERVE_FILE_BACKEND = 'filetransfers.backends.url.serve_file'
# if you need it:
PUBLIC_DOWNLOAD_URL_BACKEND = 'filetransfers.backends.url.public_download_url'
These rely on the file_field.url being set (see Django docs) and since your files will be on a separate server you probably need to look into writing a custom storage backend for Django too. (the S3 and GAE cases assume you're using the custom Django storage backends from here)

Using Django's admin interface to upload large file to GAE

I've been trying to find a way to upload a large file to GAE's datastore using Django's admin interface, but haven't found an answer that specifically addresses this issue. I'm fairly new to Python/Django, so there might be an angle that I'm not looking at.
I've been looking at the django-filetransfers solution, but I'm not sure how to integrate that into the admin interface. Any suggestions would be great!
File uploads to the appengine are handled using the blobstore and not the datastore.
https://developers.google.com/appengine/docs/python/blobstore/overview#Complete_Sample_App
The datastore filesize limit is 1 megabyte. So, attempting to upload a large file into the appengine's non-relational database isn't going to work. This is by design.
The documentation I provided above shows you how to implement large file uploads.