Django multiple photo download - python

I developed a photo gallery in python, now I want to insert a new feature, "Download Multiple Photos": a user can select some photos to download and system creates a compressed file with the photos.
In your opinion: in the frontend what is the best way to send the ids? Json? input hidden? and in the backend there is a django library that compress the selected photos and return the compressed file?
Thanks,
Marco

Once you get the IDs of all the selected image in the client, you can zip them by using the zipfile or tarfile module . The way to collect the files to compress totally depends on how did you save the image. If you save the image such as uploaded date/id/, then on the client side, you need to send those information back to the server as well to reduce the server load. Hidden fields are ok in this situation

I think the only way to do it is in the backend, because in the frontend you will only have to select which photos you want to download and send the ids or some identifiers to the server side, then retrieve those selected photos from the filesystem (based on the identifiers), compress them in a single file and return that compressed file in a response as attached content.
If you do it in the front end how would you get each file and compress them all?
Doing it in server side is the best solution in my opinion :)

Related

Is there a way to resize jpgs via http in python?

I am writing a webcrawler that finds and saves the urls of all the images on a website. I can get these without problem. I need to upload these urls, along with a thumbnail version of them, to a server via http request, which will render the image and collect feature information to use in various AI applications.
For some urls this works no problem.
http://images.asos-media.com/products/asos-waxed-parka-raincoat-with-zip-detail/7260214-1-khaki
resizes into
http://images.asos-media.com/products/asos-waxed-parka-raincoat-with-zip-detail/7260214-1-khaki?wid=200
but for actual .jpg images this method doesn't work, like for this one:
https://cdn-images.farfetch-contents.com/11/85/29/57/11852957_8811276_480.jpg
How can I resize the jpgs via url?
Resizing the image via the URL only works if the site you're hitting is using a dynamic media service or tool in their stack. That's why ASOS will allow you to append a query with the dimensions for resize, however different DM tools will have different query parameters.
If you want to make it tolerant you're best off downloading the image, resizing it with Python and then uploading it.

Download and serve image or store link to image? Scale + Security

I am building a webapp in Django that allows users to post links. When they post a link, I want to display a thumbnail image for the link. Right now, I simply download the first image on the linked page (using BeautifulSoup), store it in my Django model, and then serve it with the model.
I am wondering whether this is the best solution, from both a scale and security perspective? Would a better solution be to simply store a link to the original image on the original website, and then have the user's browse simply request that image from the linked website?
Would the second solution be faster and safer than downloading all the images onto my server? I am also worried about whether downloading and serving thousands of images will scale, as well as how to protect the app from images on malicious sites.
I think the best solution for this is to download the first image with BeautifulSoups (as you are currently doing) and then upload it to a CDN (like AmazonWS S3, Google Cloud Storage, etc) and save only the link to that image in your model. So the next time you view that link, you will just serve the image from your CDN.
This solution is very secure and can scale up!

Save image file to mySQL

I have an base64 encoded variable in my python script, it was originally an image. The images files will be around 1MB in size. I have two questions
First:
Should I decode this variable before saving it to mySQL database?
Second:
And this might depend on the previous answer. Should I save this as a BLOB or TEXT. I realize this might depend on what I am going to do with it later.
Later I am going to pull get this data from my database and display it in a website and in a iOS and android mobile app.

Form through Email that can be Parsed Using Python

I want to email out a document that will be filled in by many people and emailed back to me. I will then parse the responses using Python and load them into my database.
What is the best format to send out the initial document in?
I was thinking an interactive .pdf but do not want to have to pay for Adobe XI. Alternatively maybe a .html file but I'm not sure how easy it is to save the state of it once its been filled in in order to be emailed back to me. A .xls file may also be a solution but I'm leaning away from it simply because it would not be a particularly professional looking format.
The key points are:
Answers can be easily parsed using Python
The format should common enough to open on most computers
The document should look relatively pleasing to the eye
Send them a web-page with a FORM section, complete with some Javascript to grab the contents of the controls and send them to you (e.g. in JSON format) when they press "submit".
Another option is to set it up as a web application. There are several Python web frameworks that could be used for that. You could then e-mail people a link to the web-app.
Why don't you use Google Docs for the form. Create the form in Google Docs and save the answer in an excel sheet. And then use any python Excel format reader (Google them) to read the file. This way you don't need to parse through mails and will be performance friendly too. Or you could just make a simple form using AppEngine and save the data directly to the database.

Can I download a query as a csv?

I try download a Left Join Query with 110 columns and 60.000 rows in a CSV. I am using GAE with python and i need that the download occurs when user click in one button of my portal, but make this is imposible because always appear the DeadLineError when I execute my code.
I try use:
rpc = urlfetch.create_rpc(deadline=10, callback=None)
urlfetch.set_default_fetch_deadline(10)
urlfetch.make_fetch_call(rpc, "url",method="POST")
But this don't function.
Please, can somebody give me a mind? It's obligatory than i use GAE with python. If it's necesary more information i can give it.
To overcome the DeadlineError, On button click create a task queue for generating CSV file and save it in Blobstore. Once the file generated, Display Blobserve URL using Channel API in your page. When user click the Download URL serve the blob.
More Info:
Serving a Blob , Channel API

Categories