How to get status of uploading file in Flask - python

There is a need to add some kind of an upload progress dialog to my application. I know there are plenty of Flash/Java/HTML5 solutions for that, however they are not suitable in my case.
Flask documentation gives "an easier solution" offering Flask-Uploads extension. However I haven't found any kind of solution for my question there.
Is there any possibility to get the status of uploading file (i.e. number of bytes already uploaded)?
In fact, I know that Flask accumulates the file data in memory if file size is not big. Otherwise, it stores the file in the temporary folder. If there are no options of getting the number of received bytes, maybe there are ways of getting the temp filename at least?
Any kind of tricks are very welcome.
Thanks for help!

I don't think it is related to Flask
Please see this link:
Upload to Django with progress bar using Ajax and jQuery Laurent Luce's Blog
I think these are be helpful
request.META['REMOTE_ADDR'], request.GET['X-Progress-ID']

I've yet to test it but I found a link to something similar here

Related

jQuery file uploader - Django not working correctly with chunks

I've spent some days by now trying to figure out how to tell Django that my jQuery file uploader is sending chunks and not x seperate files.
I know that I need a custom FileUploadHandler like here in this one.
My client-side code is posted in this question.
The plugin sends chunk by chunk as a separate AJAX call (at least with FireBug it looks like this). The server accepts every one of them and saves them under a different name (in my case "_1", "_2", "_3"... ). And yes, the handler is used. I proved it via print
BTW: The Content-Range in the header is correct.
BTW II: This plugin unfortunately did not utilize chunking... so no solution here for me.
So, has anybody an idea what I might be doing wrong? I found some other FileUploadHandlers but they all seem pretty similar. So I guess the problem is not here?

Libraries for generating URL of uploading files in Django

Need to develop a project for file uploading and generating its(files's) URL, which could be shared. Are there any particular libraries or simple means in Python,(Django) that would be handy and efficient.?
~ Newbie trying a Herculean Task~ Thanks in Advance :)
Much of this is done for you in the Django-backed version of this excellent JQuery file upload app.
Try out a demo of the original here.
No. Since the Storage used may not even save the actual files on the filesystem, there is no universal way to generate a URL to them. You will need to create a view that gets passed a key that it can use to identify the record that has the file field, then you will need to respond with the file contents yourself.

Is there a tool for parsing feeds in Django

I did some googling and didn't find anything complete for my problem, but it is so generic, there has to be something.
I need feed parsing tool for my Django app (i want to fetch atom feed from somewhere and store its contents). I just found some feedparser.py references but the actual site is a long gone.
Could you provide some pointers?
feedparser is still pretty much the canonical solution for this in Python. It's very far from gone: see the documentation here and the actual project page here

Create a 'single-serving site' with python

I want to make a Python script available as a service on the net. The script, which is my first 'proper' Python program, takes a txt file as argument and writes an image into the work directory. So:
How difficult is it for somebody who is new to Python and web development?
How much work is it?
Do I need a framework (Django, cherryPy, web2py)?
Are there good tutorials?
How do I avoid the server to be compromised?
What are my next steps?
==> What is the easiest way?
In the end it is enough, if it is a white page, with some text, and a button, which when clicked, opens a file dialog. After the txt is processed, the server should just return the image, which was written on the hard drive. Already I have access to a server which has Ubuntu installed through a friend.
[update]
Thanks for all your answers. After reading them I want to stress again, that I want to have it as minimal as possible. Srikar's suggestion sounds like the easiest one:
Put it in executable directory of your OS (commonly known as CGI
path). Provide a simple HTML form & upon form submission hit this
script which executes & returns back the image you want to display.
Any objections or comments? Do you know any tutorials for that?
[udpate2]
I found this SO answer: File Sharing Site in Python Is this a sensible approach?
It's not too difficult. Actually, it sounds like a good first project.
That too subjective to answer. An hour to days.
No, you don't need one, but I'd use one if I were you. They abstract away some of the stuff you really don't care about, and you'll learn a tool you can use again in the future.
Plenty. If you want a real rundown of how Python works for the web, read the HOWTO from Python.org. If you just want to learn how to do this one project, pick a framework and do their tutorial.
This question is so broad and complex that I'm not going to try to answer it. Search this site, or Google, for questions like that.
Your next step should be to pick a framework; I've used Django successfully. Just download it, follow the installation instructions, and work your way through their tutorial; it should tell you everything you need to know to do what you want. If you still have questions once you've learned how to do the basics, come back and ask again!
Edit: The answer to that other question will certainly work for you. There, they just receive a GET request and respond with data from a Python file. You need to receive a GET request, respond with an HTML page (easy enough), then respond to a POST request that includes an uploaded file (slightly more complicated) and run your python routine on the uploaded file and then respond with the created image (or a link to it).
Take a look at this page which includes a simple Python script to do file uploads. You should easily be able to modify it to do what you want.
How difficult is it for somebody who is new to Python and web development?
Depends on your level of knowledge.
How much work is it?
Depends on which method you choose to solve the problem.
Do I need a framework (Django, cherryPy, web2py)?
Not necessarily - you could get started by using the CGI (http://docs.python.org/library/cgi.html)
Are there good tutorials?
Yes, there are plenty. The Python docs are an excellent place to start.
How do I avoid the server to be compromised?
Again, depends on the method you choose to solve the problem, although there are commonalities.
What are my next steps?
Dare I say it again, choose a method, read the docs, have a play!
If its just as simple as you have described it. Then you might not even need Django. You could simply use CGI scripting. All of these design decisions, depend on whether
You need (or foresee) a SQL storage?
or a Content-Management-System?
Will you need multiple-user support?
Do you need tight security?
Do you need different privileges for different users?
Do you need an Admin to manage your site?
If the answer to above questions is atleast 60% correct, then you might consider Django. otherwise, just write a python script. Put it in executable directory of your OS (commonly known as CGI path). Provide a simple HTML form & upon form submission hit this script which executes & returns back the image you want to display. So, it all depends on the features you need...
In the end, I created what I needed with Flask.
They have a well documented pattern / tutorial on Uploading Files. The tutorial is understandable even for people with little python and web expericence.
To get a first working version it took me 2h and the resulting code was only 50 lines. This includes, starting the webserver, having a html file/form with file upload and serving a file back to the user.

What are the different options for processing uploaded PDF files in a Django application?

Our Django application needs to do a few things with uploaded PDF files:
Verify that the file is a PDF and isn't corrupted
Check that the file isn't encrypted
Count the number of pages
We run into problems with one unfortunately popular application that's idea of an unencrypted PDF export is actually an encrypted PDF file, just with a blank password. We've been working with PyPDF to date, which is unable to read those files because the encryption is non-standard. The application exporting these files is quite popular among our users, which is a pain.
Another application exported files with a bad MIME type (something other than application/pdf), so whatever we end up using needs to be able to cope with silly choking points like that.
Is there an actively maintained, robust PDF library anywhere that we could utilize? Even PDFtk, a CLI utility that a couple people have been recommending, was last updated in 2006.
Any help is appreciated.
Update: To clarify, it can be free or paid-for. Suggest whatever you think is the best option.
PDFlib is excellent, but costs money. You didn't say it had to be free, though implicitly somehow I assume you want it to be! :)

Categories

Resources