background preloader

Google AppEngine

Facebook Twitter

Mail Python API Overview - Google App Engine. App Engine applications can send email messages on behalf of the app's administrators, and on behalf of users with Google Accounts. Apps can receive email at various addresses. Apps send messages using the Mail service and receive messages in the form of HTTP requests initiated by App Engine and posted to the app. Sending mail in Python The mail.send_mail() function sends an email message from the application. The following example sends an email message to the user as confirmation that the user created a new account with the application: import webapp2from google.appengine.api import mail class ConfirmUserSignup(webapp2.RequestHandler): def post(self): user_address = self.request.get("email_address") if not mail.is_email_valid(user_address): # prompt user to enter a valid address else: confirmation_url = createNewUserConfirmation(self.request) sender_address = "Example.com Support <support@example.com>" subject = "Confirm your registration" body = """Thank you for creating an account!

Using Google App Engine as Your Own Content Delivery Network. Do you remember, years ago, when hosting was expensive, domain names were the province of the rich, and you hosted your web pages on Geocities? It seems odd to me now that there was a time when each and every geek didn’t have his own top-level domain and super hosting setup. But as the parts became more and more affordable a man could become an outcast if he didn’t have his own slightly surreal-sounding TLD. And so it will be in the future when people realise with surprise there was a time before affordable content delivery networks.

A content delivery network, or CDN, is a system of servers spread around the world, serving files from the nearest physical location. Instead of waiting for a file to find its way from a server farm in Silicon Valley 8,000 kilometres away, I can receive it from London, Dublin, or Paris, cutting down the time I wait. The big names — Google, Yahoo, Amazon, et al — use CDNs for their sites, but they’ve always been far too expensive for us mere mortals. RESTful File Upload for AppEngine :: Thom Nichols. Google's AppEngine is an awesome platform for simple web apps. Unfortunately one of the more glaring limitations is the lack of filesystem access.

Fortunately, their robust data storage API can make up for the omission in many cases. The Use Case I wanted to have integrated image hosting for this blog so I wrote a REST handler to upload and serve image files for GAE's Python API. The Code Google's Appengine documentation actually provides the meat of the datastore code. First, a simple data model, very similar to the AppEngine documentation example: Now that we have that out of the way, here's the upload (POST handler) code: The upload from an HTML form will be a multipart-mime request.

The one last piece of information needed is the URL mapping to the ImageHandler class in main.py: Now that we're able to upload files, let's access them: A GET request will have the Image's datastore 'key' property in the URL like this example. Conclusion. Handling file uploads in App Engine. Posted by Nick Johnson | Filed under tech, app-engine, cookbook, coding This is the ninth in a series of 'Cookbook' posts describing useful strategies and functionality for writing better App Engine applications. One issue that comes up frequently on the App Engine groups is how to handle file uploads from users. Part of the confusion arises from the fact that App Engine apps cannot write to the local filesystem. Fortunately, the Datastore comes to the rescue: We can easily write an app that accepts file uploads and stores them in the datastore, then serves them back to users.

To start, we need an HTML form users can upload files through: <html><head> <title>File Upload</title></head><body> <form method="post" action="/"> <input type="file" name="file" /> <input type="submit" value="Upload" /> </form></body></html> We'll also need a datastore model we can store the uploaded file in: And finally, a Request Handler that can handle the uploads: def main(): run_wsgi_app(application) App-Engine (Java) File Upload. Java Padawan on J2ME and Android: GWT: Creating a simple File hosting site.