Uploading a file using a form in the Google App Engine to a static URL is it possible

69 views
Skip to first unread message

Matthew Rappard

unread,
Jul 30, 2015, 11:18:55 AM7/30/15
to Google App Engine
I just want to know if it's possible to make the following HTML code, work with the Google App Engine. I.E. this form will upload a file to a "STATIC" address that is stored in the Google App Engine. It can't be dyanmic it has to be the same URL across all devices. 



<html>
<form action="THE_URL" method="POST" enctype="multipart/form-data">
Application name:<input type="text" name="appname">
Application version:<input type="text" name="appversion">
Email from:<input type="text" name="emailfrom">
Email subject:<input type="text" name="emailsubject">
Crash GUID:<input type="text" name="crashguid">
MD5:<input type="text" name="md5">
Attach ZIP file:<input type="file" name="crashrpt">
<input type="submit" name="Submit">
</form>
</html> 

Barry Hunter

unread,
Jul 30, 2015, 11:29:14 AM7/30/15
to google-appengine
Yes, that sort of functionality can be implemented on AppEngine

The blobstore provides much of the functionality. But there are other ways 

Eg uploading a blob

Once uploaded, can 'serve' the blob


You can make your handler work on any device. Its dynamic in that its processed by a script (to figure out what blob to serve) - but its static, in that the URL itself doesnt need to change, and can persist long term. 


Can also use Google Storage instead
... once uploaded to Storage, it has a URL for direct access to the uploaded file. 


Matthew Rappard

unread,
Jul 30, 2015, 11:59:43 AM7/30/15
to Google App Engine, barryb...@gmail.com
Okay so my thing is Blobstore works by creating a dynamic that you call via blobstore.create_upload_url() which would be great, if I could get the dyanmic URL but I can't hence the need for a static URL.

Barry Hunter

unread,
Jul 30, 2015, 12:18:12 PM7/30/15
to google-appengine
So your problem is that create_upload_url creates a long, verbose url. One not repeatable?

You want a nice simple 'endpoint' to upload to?

could directly handle the POST yourself in a dynamic handler (accept the uploaded file directly) 

Its a little more tricky to then send the file to the BlobStore - esp with the deprecation of the Files API. 

... probably easier to then send the file direct to Google Storage. 


--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/d1475ae7-9a40-4c7e-8884-e418aaf19823%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matthew Rappard

unread,
Jul 30, 2015, 12:36:41 PM7/30/15
to Google App Engine, barryb...@gmail.com
The issue is that the URL becomes inactive after X amount of time, as well as the code I sent is really just a proxy for what a C++ library is doing.

I don't really need it in the Google App engine, I just need to be stored somewhere so even turning it into an email attachment and mailing it would be fine.

The code 

class CrashUploader(webapp2.RequestHandler):
    def post(self):
        file_data = self.request.get("crashrpt",default_value='This Failed');
 
grabs something. Does anyone know if I can use mail.send_mail to send it out as an attachment.

Barry Hunter

unread,
Jul 30, 2015, 12:47:52 PM7/30/15
to Matthew Rappard, Google App Engine

I don't really need it in the Google App engine, I just need to be stored somewhere so even turning it into an email attachment and mailing it would be fine.

The code 

class CrashUploader(webapp2.RequestHandler):
    def post(self):
        file_data = self.request.get("crashrpt",default_value='This Failed');
 
grabs something. Does anyone know if I can use mail.send_mail to send it out as an attachment.

Yes

So your dynamic handler could just accept the file, and immidiately send it out. Rather than storing it somewhere. 


Matthew Rappard

unread,
Jul 30, 2015, 1:37:18 PM7/30/15
to Google App Engine, barryb...@gmail.com
If anyone is following here code that is working

class CrashUploader(webapp2.RequestHandler):
    def post(self):
        attachments = self.request.POST.get('crashrpt')
        entity = DatastoreFile(data=attachments.value, mimetype=attachments.type)
        entity.appname =self.request.get('appname')
        entity.appversion =self.request.get('appversion')
        entity.emailfrom =self.request.get('emailfrom')
        entity.crashguid =self.request.get('crashguid')
        entity.md5 =self.request.get('md5')
        entity.put()
        file_url = "http://%s/%d/%s" % (self.request.host, entity.key().id(), file.name)
        self.response.out.write("Your uploaded file is now available at %s" % (file_url,))
        mail.send_mail(sender="YOUR_SITE",
                   to="THE ACCOUNT YOU WANT THEM TO GO TO",
                   subject="Crash Report",
                   body="""
Attached is the document file you requested. Is at %s

"""%file_url)

class CrashDownload(webapp.RequestHandler):
    def get(self, id, filename):
      entity = DatastoreFile.get_by_id(int(id))
      self.response.headers['Content-Type'] = 'application/zip'
      self.response.out.write(entity.data)
Reply all
Reply to author
Forward
0 new messages