Exemplo n.º 1
0
 def post(self):
     user = users.get_current_user()        
     file = self.request.POST['file']
     
     # no need to retrieve the Account entity, just link it by userId which is the key
     entity = DatastoreFile(data=file.value, mimetype=file.type, userId=user.user_id())
     entity.put()
     file_url = "http://%s/file/download/%d" % (self.request.host, entity.key.id())
     
     # or you can link this entity to other entity (e.g. link to an album)
     self.response.out.write("Your uploaded file is now available at <a href='%s'>%s</a>" % (file_url,file_url))        
Exemplo n.º 2
0
    def post(self, slug):
        project = Project.all().filter('slug =', slug).fetch(1)[0]
        try:
            file = self.request.POST['file']

            f = DatastoreFile(data=file.value, mimetype=file.type, project=project, name=file.filename)
            f.put()

            url = "http://%s/file/%s/%d/%s" % (self.request.host, slug, f.key().id(), f.name)
        except Exception, e:
            logging.error("error uploading file: %s" % e)