Ejemplo n.º 1
0
 def post(self):
     album = self.request.get("album")
     name = urllib.unquote(self.request.get("qqfile"))
     bf = self.request.body
     mime = getImageInfo(bf)[0]
     album = Album.get_by_key_name(album)
     if mime.find('image') > -1 and album:
         img = Image.add(album, name, mime, bf)
         return self.response.out.write("{success:true}")
     return self.response.out.write("{success:false}")
Ejemplo n.º 2
0
Archivo: api.py Proyecto: v998/sa3album
 def get(self, slug):
     album = Album.get_by_key_name(slug)
     if album is None:
         return self.error(404)
     self.template_value['album'] = (album.name, album.slug, album.count,
                                     album.url)
     self.template_value['imgs'] = [
         (img.name, img.size, img.f, img.s)
         for img in Image.all().filter('album =', album)
     ]
     return self.render()
Ejemplo n.º 3
0
 def post(self):
     bf = self.request.get("file")
     if not bf:
         return self.redirect("/a/upload/common/")
     name = unicode(self.request.body_file.vars['file'].filename, 'utf-8')
     mime = self.request.body_file.vars['file'].headers['content-type']
     #handle file > 1M
     if mime.find('image') == -1:
         self.redirect("/a/upload/common/")
     album = Album.get_by_key_name(self.request.get("album"))
     Image.add(album, name, mime, bf)
     self.redirect(album.url)
Ejemplo n.º 4
0
 def post(self):
     skey = self.request.get("skey")
     logging.info(skey)
     if skey != self.settings.skey:
         self.response.out.write("")
     try:
         album = self.request.get("album")
         bf = self.request.get("Filedata")
         name = unicode(self.request.body_file.vars["Filedata"].filename,'utf-8')
         mime = getImageInfo(bf)[0]
         album = Album.get_by_key_name(album)
         img =Image.add(album,name,mime,bf)
         self.response.out.write(img.copyurl)
     except:
         self.response.out.write("")
Ejemplo n.º 5
0
Archivo: api.py Proyecto: v998/sa3album
 def put(self, slug, name):
     '''Put a image file
     '''
     album = Album.get_by_key_name(slug)
     if album is None:
         return self.error(404)
     name = urllib.unquote(name).decode('utf-8')
     mime = get_mime(name)
     bf = self.request.body
     if len(bf) > 1000 * 1000:
         return self.error(411)
     try:
         img = Image.add(album, name, mime, bf)
         self.template_value['key'] = img.key().name()
         self.template_value['f'] = img.f
         self.template_value['s'] = img.s
         return self.render()
     except:
         return self.error(500)
Ejemplo n.º 6
0
    def post(self):
        album = self.request.get("album")
        u = self.request.get("u")
        des = self.request.get("des")
        name = self.request.get("name")
        retries = 3
        result = None
        try:
            result = urlfetch.fetch(u, deadline=10)
        except:
            retries -= 1
            if retries > 0:
                result = urlfetch.fetch(u, deadline=10)

        if result and result.status_code == 200:
            album = Album.get_by_key_name(album)
            bf = result.content
            mime = getImageInfo(bf)[0]
            if mime.find("image") < 0:
                raise Exception(u"不是正確的圖片")
            img = Image.add(album, name, mime, bf, **{"description": des})
            self.redirect(album.m_url)
        else:
            self.response.out.write(u"此地址抓取錯誤")