<p>I am planning to create a web app that allows users to downgrade their visual studio project files. However, It seems Google App Engine accepts files uploading and flat file storing on the Google Server through <code>db.TextProperty</code> and <code>db.BlobProperty</code>.</p>

<p>I'll be glad anyone can provide code sample (both the client and the server side) on how this can be done.</p>

[{'answer_id': 81479, 'author': 'Guido', 'author_id': 12388, 'author_profile': 'https://Stackoverflow.com/users/12388', 'pm_score': 1, 'selected': False, 'text': '<p>You can not store files as there is not a traditional file system.  You can only store them in their own DataStore (in a field defined as a <a href="http://code.google.com/appengine/docs/datastore/typesandpropertyclasses.html" rel="nofollow noreferrer">BlobProperty</a>)</p>\n\n<p>There is an example in the previous link:</p>\n\n<pre><code>class MyModel(db.Model):\n  blob = db.BlobProperty()\n\nobj = MyModel()\nobj.blob = db.Blob( file_contents )\n</code></pre>\n'}, {'answer_id': 81489, 'author': 'David Webb', 'author_id': 3171, 'author_profile': 'https://Stackoverflow.com/users/3171', 'pm_score': 0, 'selected': False, 'text': '<p>There\'s no flat file storing in Google App Engine.  Everything has to go in to the <a href="http://code.google.com/appengine/docs/datastore/" rel="nofollow noreferrer">Datastore</a> which is a bit like a relational database but not quite.</p>\n\n<p>You could store the files as <a href="http://code.google.com/appengine/docs/datastore/typesandpropertyclasses.html#TextProperty" rel="nofollow noreferrer">TextProperty</a> or <a href="http://code.google.com/appengine/docs/datastore/typesandpropertyclasses.html#BlobProperty" rel="nofollow noreferrer">BlobProperty</a> attributes.</p>\n\n<p>There is a 1MB limit on DataStore entries which may or may not be a problem.</p>\n'}, {'answer_id': 143798, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>There is a thread in Google Groups about it:</p>\n\n<p><a href="http://groups.google.com/group/google-appengine/browse_thread/thread/f9d0f22d8de8c025/bba32165e308dd13?lnk=gst&amp;q=uploading+files#bba32165e308dd13" rel="noreferrer">Uploading Files</a></p>\n\n<p>With a lot of useful code, that discussion helped me very much in uploading files.</p>\n'}, {'answer_id': 173918, 'author': 'sastanin', 'author_id': 25450, 'author_profile': 'https://Stackoverflow.com/users/25450', 'pm_score': 6, 'selected': False, 'text': '<p>In fact, this question is answered in the App Egnine documentation. See an example on <a href="http://code.google.com/appengine/docs/images/usingimages.html#Uploading" rel="noreferrer">Uploading User Images</a>.</p>\n\n<p>HTML code, inside &lt;form&gt;&lt;/form&gt;:</p>\n\n<pre>&lt;input type="file" name="img"/&gt;</pre>\n\n<p>Python code:</p>\n\n<pre>class Guestbook(webapp.RequestHandler):\n  def post(self):\n    greeting = Greeting()\n    if users.get_current_user():\n      greeting.author = users.get_current_user()\n    greeting.content = self.request.get("content")\n    avatar = self.request.get("img")\n    greeting.avatar = db.Blob(avatar)\n    greeting.put()\n    self.redirect(\'/\')</pre>\n'}, {'answer_id': 534354, 'author': 'Joe Petrini', 'author_id': 53488, 'author_profile': 'https://Stackoverflow.com/users/53488', 'pm_score': 2, 'selected': False, 'text': '<p>If your still having a problem, check you are using enctype in the form tag</p>\n\n<p>No:</p>\n\n<pre><code>&lt;form encoding="multipart/form-data" action="/upload"&gt;\n</code></pre>\n\n<p>Yes:</p>\n\n<pre><code>&lt;form enctype="multipart/form-data" action="/upload"&gt;\n</code></pre>\n'}, {'answer_id': 1240820, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Personally I found the tutorial described <a href="http://shogi-software.blogspot.com/2009/04/google-app-engine-and-file-upload.html" rel="nofollow noreferrer">here</a> useful when using the Java run time with GAE. For some reason, when I tried to upload a file using</p>\n\n<pre><code>&lt;form action="/testservelet" method="get" enctype="multipart/form-data"&gt;\n    &lt;div&gt;\n        Myfile:&lt;input type="file" name="file" size="50"/&gt;\n    &lt;/div&gt;\n\n    &lt;div&gt;\n        &lt;input type="submit" value="Upload file"&gt;\n    &lt;/div&gt;\n&lt;/form&gt;\n</code></pre>\n\n<p>I found that my HttpServlet class for some reason wouldn\'t accept the form with the \'enctype\' attribute. Removing it works, however, this means I can\'t upload any files.</p>\n'}, {'answer_id': 1987486, 'author': 'jbochi', 'author_id': 230636, 'author_profile': 'https://Stackoverflow.com/users/230636', 'pm_score': 3, 'selected': False, 'text': '<p>Google has released a service for storing large files. Have a look at <a href="http://code.google.com/appengine/docs/python/blobstore/" rel="nofollow noreferrer">blobstore API documentation</a>. If your files are > 1MB, you should use it.</p>\n'}, {'answer_id': 3050807, 'author': 'Bili', 'author_id': 331191, 'author_profile': 'https://Stackoverflow.com/users/331191', 'pm_score': 3, 'selected': False, 'text': '<p>I try it today, It works as following:</p>\n\n<p>my sdk version is 1.3.x</p>\n\n<p>html page:</p>\n\n<pre><code>&lt;form enctype="multipart/form-data" action="/upload" method="post" &gt; \n&lt;input type="file" name="myfile" /&gt; \n&lt;input type="submit" /&gt; \n&lt;/form&gt; \n</code></pre>\n\n<p>Server Code:</p>\n\n<pre><code>file_contents = self.request.POST.get(\'myfile\').file.read() \n</code></pre>\n'}, {'answer_id': 3545032, 'author': 'Honza Pokorny', 'author_id': 244182, 'author_profile': 'https://Stackoverflow.com/users/244182', 'pm_score': 0, 'selected': False, 'text': '<p>I have observed some strange behavior when uploading files on App Engine. When you submit the following form:</p>\n\n<pre><code>&lt;form method="post" action="/upload" enctype="multipart/form-data"&gt;\n    &lt;input type="file" name="img" /&gt;\n    ...\n&lt;/form&gt;\n</code></pre>\n\n<p>And then you extract the <code>img</code> from the request like this:</p>\n\n<pre><code>img_contents = self.request.get(\'img\')\n</code></pre>\n\n<p>The <code>img_contents</code> variable is a <code>str()</code> in Google Chrome, but it\'s unicode in Firefox. And as you now, the <code>db.Blob()</code> constructor takes a string and will throw an error if you pass in a unicode string. </p>\n\n<p>Does anyone know how this can be fixed?</p>\n\n<p>Also, what I find absolutely strange is that when I copy and paste the Guestbook application (with avatars), it works perfectly. I do everything exactly the same way in my code, but it just won\'t work. I\'m very close to pulling my hair out.</p>\n'}, {'answer_id': 4787543, 'author': '101010', 'author_id': 451007, 'author_profile': 'https://Stackoverflow.com/users/451007', 'pm_score': 7, 'selected': True, 'text': '<p>Here is a complete, working file.  I pulled the original from the Google site and modified it to make it slightly more real world.</p>\n\n<p>A few things to notice:</p>\n\n<ol>\n<li>This code uses the <a href="http://code.google.com/appengine/docs/python/blobstore/" rel="noreferrer">BlobStore API</a></li>\n<li><p>The purpose of this line in the\nServeHandler class is to "fix" the\nkey so that it gets rid of any name\nmangling that may have occurred in\nthe browser (I didn\'t observe any in\nChrome)</p>\n\n<pre><code>blob_key = str(urllib.unquote(blob_key))\n</code></pre></li>\n<li><p>The "save_as" clause at the end of this is important.  It will make sure that the file name does not get mangled when it is sent to your browser.  Get rid of it to observe what happens.</p>\n\n<pre><code>self.send_blob(blobstore.BlobInfo.get(blob_key), save_as=True)\n</code></pre></li>\n</ol>\n\n<p>Good Luck!</p>\n\n<pre><code>import os\nimport urllib\n\nfrom google.appengine.ext import blobstore\nfrom google.appengine.ext import webapp\nfrom google.appengine.ext.webapp import blobstore_handlers\nfrom google.appengine.ext.webapp import template\nfrom google.appengine.ext.webapp.util import run_wsgi_app\n\nclass MainHandler(webapp.RequestHandler):\n    def get(self):\n        upload_url = blobstore.create_upload_url(\'/upload\')\n        self.response.out.write(\'&lt;html&gt;&lt;body&gt;\')\n        self.response.out.write(\'&lt;form action="%s" method="POST" enctype="multipart/form-data"&gt;\' % upload_url)\n        self.response.out.write("""Upload File: &lt;input type="file" name="file"&gt;&lt;br&gt; &lt;input type="submit" name="submit" value="Submit"&gt; &lt;/form&gt;&lt;/body&gt;&lt;/html&gt;""")\n\n        for b in blobstore.BlobInfo.all():\n            self.response.out.write(\'&lt;li&gt;&lt;a href="/serve/%s\' % str(b.key()) + \'"&gt;\' + str(b.filename) + \'&lt;/a&gt;\')\n\nclass UploadHandler(blobstore_handlers.BlobstoreUploadHandler):\n    def post(self):\n        upload_files = self.get_uploads(\'file\')\n        blob_info = upload_files[0]\n        self.redirect(\'/\')\n\nclass ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):\n    def get(self, blob_key):\n        blob_key = str(urllib.unquote(blob_key))\n        if not blobstore.get(blob_key):\n            self.error(404)\n        else:\n            self.send_blob(blobstore.BlobInfo.get(blob_key), save_as=True)\n\ndef main():\n    application = webapp.WSGIApplication(\n          [(\'/\', MainHandler),\n           (\'/upload\', UploadHandler),\n           (\'/serve/([^/]+)?\', ServeHandler),\n          ], debug=True)\n    run_wsgi_app(application)\n\nif __name__ == \'__main__\':\n  main()\n</code></pre>\n'}, {'answer_id': 11814685, 'author': 'vivek_jonam', 'author_id': 586836, 'author_profile': 'https://Stackoverflow.com/users/586836', 'pm_score': 0, 'selected': False, 'text': '<p>There is a way of using <strong>flat file system</strong>( Atleast in usage perspective)</p>\n\n<p>There is this <a href="http://code.google.com/p/gaevfs/" rel="nofollow"><strong>Google App Engine Virtual FileSystem project</strong></a>. that is implemented with the help of datastore and memcache APIs to emulate an ordinary filesystem. Using this library you can use in you project a <strong>similar filesystem access(read and write)</strong>.</p>\n'}]
['https://Stackoverflow.com/questions/81451', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3834/']