Commits

Anonymous committed 8bc343f

添加html5上传

Comments (0)

Files changed (3)

 import string
 import re
 import random
+import urllib
 import os
 from google.appengine.api import urlfetch
 from google.appengine.ext import webapp
 from util.handler import AdminHandler,get_or_404
 from util.paging import PagedQuery
 from util.base import filter_url
+from util.getimageinfo import getImageInfo
 from util import oauth
 from django.utils import simplejson
 from models import Album,Image,Setting as S
         self.template_value['album-select'] = self.request.get("album","")
         self.render('upload.html')
         
+class ImageHtml5UploadHandler(AdminHandler):
+    def get(self):
+        self.template_value['albums']=Album.all()
+        self.template_value['album-select'] = self.request.get("album","")
+        self.render('upload-html5.html')
+        
+    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 len(bf) < 1024*1024 and album:
+            img =Image.add(album,name,mime,bf)
+            return self.response.out.write("{success:true}")
+        return self.response.out.write("{success:false}")
+        
 class ImageDelHandler(AdminHandler):
     def get(self):
         key_name = self.request.get("key")
                                         
                                         ('/a/upload/common/',CommonImageUploadHandler),
                                         ('/a/upload/',ImageUploadHandler),
+                                        ('/a/upload5/',ImageHtml5UploadHandler),
                                         ('/a/img/del/',ImageDelHandler),
                                         ('/a/img/updatedes/',ImageUpdateDesHandler),
                                         ('/a/settings/',SystemSettingsHandler),
     twitter_user = db.StringProperty()
     twitter_auto = db.BooleanProperty(default=False)
 
-    version = '0.2.1'
+    version = '0.2.3'
     
     @classmethod
     def get_s(cls):

themes/admin/upload.html

 		{% endfor %}
     </select>
     <a href="/a/album/add/">新建相册</a>
+	<a href="/a/upload5/">尝试html5上传</a>
 <p>
 	<input id="fileinput" name="fileinput" type="file" />
     <input id="skey" name="skey" value="{{settings.skey}}" type="hidden">