[Flask] Serving a file to downalod AND print message on screen

Ulrich Berthold ub at artfacts.net
Wed Nov 22 08:07:22 EST 2017


hey abhinav,


On Tue, Nov 21, 2017 at 07:30:02PM +0000, Kumar, Abhinav wrote:
> Thanks for your thoughts.
> 
> I can serve the file if I put it in 'static' folder, but not in 'upload' folder.
> I guess 'static' is exposed by default.
> I am not sure how to expose any other folder like 'upload'.
did you have a look at the fileupload pattern?
http://flask.pocoo.org/docs/0.12/patterns/fileuploads/

it does exactly what you want, upload a file to a configurable upload
folder and consequently serve the file from that location.

hope that helps .. all the best,
ub


> Thanks,
> Abhinav
> 
> 
> ________________________________
> From: Flask [flask-bounces+akumar=intrexon.com at python.org] on behalf of sidwoodstock . [sidwoodstock at gmail.com]
> Sent: Tuesday, November 21, 2017 9:35 AM
> To: flask at python.org
> Subject: Re: [Flask] Serving a file to downalod AND print message on screen
> 
> Just some thoughts:
> 
> - Verify file is truly placed in /uploads/
> - Verify your file server is exposing your uploads directory.
> - You can move around the code in your template which shows flashed messages, perhaps move it to a place which gets called when you want.
> 
> To truly help with the uploads / file not found issue, it'd be helpful to know what other packages you're using.
> 
> 
> Scott Woodstock
> 
> 
> 
> On Fri, Nov 17, 2017 at 9:00 AM, <flask-request at python.org<mailto:flask-request at python.org>> wrote:
> Send Flask mailing list submissions to
>         flask at python.org<mailto:flask at python.org>
> 
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://mail.python.org/mailman/listinfo/flask
> or, via email, send a message with subject or body 'help' to
>         flask-request at python.org<mailto:flask-request at python.org>
> 
> You can reach the person managing the list at
>         flask-owner at python.org<mailto:flask-owner at python.org>
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Flask digest..."
> 
> 
> Today's Topics:
> 
>    1. Re: Serving a file to downalod AND print message on screen
>       (Geert Stappers)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Thu, 16 Nov 2017 21:16:10 +0100
> From: Geert Stappers <stappers at stappers.nl<mailto:stappers at stappers.nl>>
> To: flask at python.org<mailto:flask at python.org>
> Subject: Re: [Flask] Serving a file to downalod AND print message on
>         screen
> Message-ID: <20171116201610.GX21385 at gpm.stappers.nl<mailto:20171116201610.GX21385 at gpm.stappers.nl>>
> Content-Type: text/plain; charset=us-ascii
> 
> On Wed, Nov 15, 2017 at 05:47:19PM +0000, Kumar, Abhinav wrote:
> > Hi,
> >
> > After I process some data, I want to write log output to the screen and let user download the results as a zip file.
> >
> > I tried flash, but that does not print message until the app is executed next time.
> >
> > I can't possible use two return statements (one for send_file for download and other for rendering a template).
> >
> > I could use only template rendering and provide a link to download the results file in the template html file, but that link says 'file not found'...
> >
> > In my template file I have code like
> >     Please download the result  <a href=/upload/results.zip>here</a>
> > And I place the results.zip file in "upload" folder before calling render_template.
> >
> > But the app says "The requested URL was not found on the server"
> > The URL it points to is "http://akumar-linux2:5000/upload/results.zip"
> >
> 
> FWIW   I read above _two_ problems:
>  * URL not found
>  * wanting to write to screen
> 
> 
> Advice: Start with fixing the "URL not found".
> 
> 
> 
> 
> 
> Groeten
> Geert Stappers
> Seen both postings from original poster, replying on one.
> --
> Leven en laten leven
> 
> 
> ------------------------------
> 
> Subject: Digest Footer
> 
> _______________________________________________
> Flask mailing list
> Flask at python.org<mailto:Flask at python.org>
> https://mail.python.org/mailman/listinfo/flask
> 
> 
> ------------------------------
> 
> End of Flask Digest, Vol 29, Issue 3
> ************************************
> 
> 
> ________________________________
> 
> CONFIDENTIAL TRANSMISSION - To the extent this electronic communication or any of its attachments contain information that is not in the public domain, such information is considered by Intrexon Corporation to be confidential and proprietary. This communication is expected to be read and/or used only by the individual(s) for whom it is intended. If you have received this electronic communication in error, please reply to the sender advising of the error in transmission and delete the original message and any accompanying documents from your system immediately, without copying, reviewing or otherwise using them for any purpose. Thank you for your cooperation.

> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/flask/attachments/20171122/a6a635ef/attachment.sig>


More information about the Flask mailing list