librelist archives

« back to archive

Securing Images

Securing Images

From:
Jonathan Chen
Date:
2012-08-28 @ 22:27
Hey all,

I'm looking into having images secured. What I mean is that I am looking
into having some images for public consumptions and some images for private
consumption.The issue I am running into is to have images not available to
public usage. I tried to stuff images into a static folder, but I am
finding that the static folders are available to the public even the
blueprints.

What methods are available to use?

~Jonathan C.

Re: [flask] Securing Images

From:
kates
Date:
2012-08-28 @ 22:37
# something like this should do.
from flask import send_from_directory
@app.route("/download/<filename>")
def download(filename):
  if "userid" in session:
    return send_from_directory("/path/to/upload/folder", filename, 
as_attachment=True)
  return abort(403)

On 29 Aug, 2012, at 6:27 AM, Jonathan Chen <tamasiaina@gmail.com> wrote:

> Hey all,
> 
> I'm looking into having images secured. What I mean is that I am looking
into having some images for public consumptions and some images for 
private consumption.The issue I am running into is to have images not 
available to public usage. I tried to stuff images into a static folder, 
but I am finding that the static folders are available to the public even 
the blueprints.
> 
> What methods are available to use?
> 
> ~Jonathan C.

Re: [flask] Securing Images

From:
Jonathan Chen
Date:
2012-08-28 @ 22:41
thanks, I di dnot know that existed :)

~Jonathan C.


On Tue, Aug 28, 2012 at 3:37 PM, kates <katesgasis@gmail.com> wrote:

> # something like this should do.
> from flask import send_from_directory
> @app.route("/download/<filename>")
> def download(filename):
>   if "userid" in session:
>     return send_from_directory("/path/to/upload/folder", filename,
> as_attachment=True)
>   return abort(403)
>
> On 29 Aug, 2012, at 6:27 AM, Jonathan Chen <tamasiaina@gmail.com> wrote:
>
> > Hey all,
> >
> > I'm looking into having images secured. What I mean is that I am looking
> into having some images for public consumptions and some images for private
> consumption.The issue I am running into is to have images not available to
> public usage. I tried to stuff images into a static folder, but I am
> finding that the static folders are available to the public even the
> blueprints.
> >
> > What methods are available to use?
> >
> > ~Jonathan C.
>
>

Re: [flask] Securing Images

From:
Steven Kryskalla
Date:
2012-08-28 @ 22:52
> On Tue, Aug 28, 2012 at 3:37 PM, kates <katesgasis@gmail.com> wrote:
>>
>> # something like this should do.
>> from flask import send_from_directory
>> @app.route("/download/<filename>")
>> def download(filename):
>>   if "userid" in session:
>>     return send_from_directory("/path/to/upload/folder", filename,
>> as_attachment=True)
>>   return abort(403)
>>

You can also put this kind of authorization code into
@app.before_request or @blueprint.before_request.