I am doing a project. It is using a File system(1GB File) rather than a database. I created the front end using angular. I wrote a Python-Flask-Server that handles the requests from the client( Browser) and dispatches the respective html files. However, I want to save all the users( Username and Password) regestered in a 1GB file for server side storage. Where should I start now?. Any resources ? Please help.
Related
I tried to download a document in my telegram bot hosted in heroku, but in the server (heroku) the file don´t send to user, when this make a request.
In local it´s right and function, the document send with no problem.
This is the code, i use the library gdown to download file to Google Drive:
url = 'link to document in drive (mode view for all with link)'
output = 'List.pdf'
doc = gdown.download(url, output, quiet=False)
bot.sendDocument(chat_id=ChatId, document=open('list.pdf', 'rb'), filename=output)
In local runing the file is downloading without problem
But if i send to heroku server with docker and start service, the bot not send to user the PDF.
I created an if when FileNotFoundError (because that error sheds heroku), but always goes to if, and not send the file (I puted a link to view the document, but is not the same)
¿Any idea to solve?
On my webpage served by a Debian web server hosted by amazon-lightsail behind nginx and gunicorn, a user can send a request to start a Django view function. This function add some work to a background process and check every 5s if the background process created a file. If the file exists, the view sends a response and the user can download the file. Sometimes this process can take a long time and the user get a 502 bad gateway message. If the process takes too long, I like to send the user an email with a link where he can download the file from the web server. I know how to send the email after the process is finished, but I don't know how to serve the file to the user by a download link.
This is the end of my view function:
print('######### Serve Downloadable File #########')
while not os.path.exists(f'/srv/data/ship_notice/{user_token}'):
print('wait on file is servable')
time.sleep(5)
# Open the file for reading content
path = open(filepath, 'r')
# Set the mime type
mime_type, _ = mimetypes.guess_type(filepath)
# Set the return value of the HttpResponse
response = HttpResponse(path, content_type=mime_type)
# Set the HTTP header for sending to browser
response['Content-Disposition'] = f"attachment; filename={filename}"
# Return the response value
return response
Another model function which sends the mail to the user after process is finished:
def send_mail_precipitation(filepath, user_token, email):
from django.core.mail import EmailMessage
import time
import os
while not os.path.exists(f'/srv/data/ship_notice/{user_token}'):
print('wait 30secs')
time.sleep(30)
msg = EmailMessage(
subject = 'EnviAi data',
body = 'The process is finished, you can download the file here.... ',
to = [email]
)
msg.send()
The file is too big to send it with msg.attach_file(filepath)
What options do I have to send the user a link to download these files. Do I need to set up a ftp server/folder, or what kind of options do I have? And what kind of work do I have to do when I want that the link is only 72h valid? Thanks a lot!
Update
One way would be to copy the file to the static folder, which is available to the public. Should I avoid this approach for any reason?
Not a straight answer but a possible way to go.
Such a long-running tasks are usually implemented with additional tool like Celery. It is a bad practice to let view/api endpoint run as long as it takes and keep requesting process waiting until completed. Good practice is to give response as fast as you can.
In your case it would be:
create a celery task to build your file (creating a task is fast)
return task id in response
request task status from frontend with given task id
when task is done file URL should be returned
It is also possible to add on_success code which will be executed (started by Celery automatically) when task is done. You can call your email_user_when_file_is_ready function in reaction on this event.
To make files downloadable you can add a location to the nginx config same as you did for static and media folders. Put your files to the location mapped folder and that's it. Give the user URL to your file.
I am wondering whether Flask app in Google App Engine Production server can receive email with attachment from gmail or any other third party.
As I am having a requirement now that I would receive a email with csv attachment, need to parse it - take the decision and change the content on the website.
I am thinking of automating the entire thing, but I do no how to setup mail with google app engine, that is my application whenever receive a mail with attachment, parse it, do the computations and change the page content and display on the website.
I have gone through google app engine document but it doesn't provide much information.
I have setup the inbound_email in app.yaml and also handlers for the email, now the only question is how to get the email to the handler script. enter link description here
Is there any way on doing the above requirements ???
So I want to send an email from Django/Python hosted with Heroku with an attachment (PDF) located in an S3 bucket. So I can send an email with a file attachment that is locally stored but I can't find a way to attach a remotely hosted file to an email.
As an additional point, I'm trying to use Mandrill but this isn't the main requirement.
I'm simply trying to send an email from python/django with an attachment without having to save the attachment locally first (as this isn't recommended/possible/ideal with my Heroku setup)
This is simple enough, assuming your file is stored as a normal file field (with a different storage selected), then you can do the following:
message = EmailMessage(subject, body, from_email, bcc=recipient_list)
message.attach(FILENAME, mymodel.myfilefield.read())
This will just download the file from S3 temporarily into the memory and send the email with the attachment without the necessity to use the local filesystem.
My school has a webdav file server that contains files that I frequently need to download. For this server, I have a username and password that I can use to connect to the server, and If I go to the URL in chrome I can view everything just fine. Now my question is, how can I access and login to this WebDAV server with python, and then download files from it. I have been unable to find anything with google and apologize if there was a very simple solution that I missed.
You can use python-webdav-library
from webdav import WebdavClient
url = 'https://somesite.net'
mydav = WebdavClient.CollectionStorer(url, validateResourceNames=False)
mydav.connection.addBasicAuthorization(<username>, <password>)
mydav.path = <path to file I want, ie '/a/b/c.txt'>
mydav.downloadFile(<local path ie. ~/Downloads/c.txt>)
Can't you use:
#codesnippet
import webbrowser
webbrowser.open("URL")
Replace "URL" with the web address of the file stored on the internet
server.