Commits

Anonymous committed 48fde22

最大图片支持10M

Comments (0)

Files changed (7)

         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 len(bf) > 1000*1000 or mime.find('image')==-1:
+        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)
         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:
+        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}")
         img.put()
         mime = str(img.mime) if w ==0 and h==0 else "image/jpeg"
         bf = img.get_resize_img(w,h)
+        logging.info(len(bf))
         self.response.headers['Content-Type'] = mime
         self.response.headers['ETag']=key
         self.response.headers['Cache-Control']="max-age=315360000"
         h = int(self.request.get("h","0"))
         mime = 'image/jpeg' 
         self.response.headers['Content-Type'] = mime
-        self.response.out.write(resize(img.bf,(w,h)))
+        self.response.out.write(resize(img.body,(w,h)))
         
 class ImagePageHandler(PublicHandler):
     def get(self,key_name):
         img = get_or_404(Image.get_by_key_name_with_cache,key_name)
         self.response.headers['Content-Type'] = "application/octet-stream; CHARSET=utf8"
         self.response.headers['Content-Disposition']='attachment; filename=%s' % img.name.encode('utf-8')
-        self.response.out.write(img.bf)
+        self.response.out.write(img.body)
         
 class LogoutHandler(PublicHandler):
     def get(self):
     def put(self):
         if self.is_saved():
             memcache.delete("f::%s" % self.key().name())
-        else:  #calc image md5
-            self.md5 = get_md5(self.bf)
         super(Image,self).put()
     
     def delete(self):
         return Image.all().filter('album =',self.album).order('-created').filter('created <', self.created).get()
     
     @property
+    def body(self):
+        return self.bf or ''.join([f.bf for f in self.bfs])
+    
+    @property
     def des(self):
         '''
         Return image description,default :imgage name
         data = memcache.get(key)
         if data is None:
             logging.info("generate thumb image key:%s" % key)
-            data = resize(self.bf,(w,h))
-            memcache.set(key,data,3600*24)
+            data = resize(self.body,(w,h))
+            #make true data size < 1000000
+            if len(data) < 1000000:
+                memcache.set(key,data,3600*24)
         return data
         
     @classmethod
             return img
         
         key_name = Counter.get_max('image')
-        img = Image(album=album,name=name,mime=mime,bf=bf,key_name = key_name,**kwargs)
-        img.size = len(img.bf)
+        size = len(bf)
+        start =0
+        splitelen=1000*1000 # 1M limit  
+        if size <= splitelen:
+            img = Image(album=album,name=name,mime=mime,bf=bf,key_name = key_name,size=size,**kwargs)
+        else:
+            img = Image(album=album,name=name,mime=mime,key_name = key_name,size=size,**kwargs)
+            while start<img.size:
+                ibf = ImageBF(bf=bf[start:start+splitelen],image = img)
+                ibf.put()
+                start+=splitelen
+            
         t = images.Image(image_data=bf)
         img.width = t.width
         img.height = t.height
+        img.md5 = get_md5(bf)
         img.put()
         return img
+    
     @classmethod
     def get_by_key_name_with_cache(cls,key_name):
         key = "f::%s" % key_name
             memcache.set(key,data,3600*24)
         return data
             
+class ImageBF(db.Model):
+    '''Image binary file'''
+    bf = db.BlobProperty()
+    image = db.ReferenceProperty(Image,collection_name='bfs')
     
 class Counter(db.Model):
     '''
         return obj.value
        
     
+    
+    
 class Setting(db.Model):
     name = db.StringProperty()
     theme = db.StringProperty()
     twitter_user = db.StringProperty()
     twitter_auto = db.BooleanProperty(default=False)
 
-    version = '0.2.5'
+    version = '0.2.6'
     path = "http://%s" % os.environ['HTTP_HOST']
     
     @classmethod

static/fileuploader.css

 .qq-upload-size,.qq-upload-cancel {font-size:11px;}
 
 .qq-upload-failed-text {display:none;}
-.qq-upload-fail .qq-upload-failed-text {display:inline;}
+.qq-upload-fail .qq-upload-failed-text {display:inline;}
+
+.graph{
+	border: 1px solid #B1D632; 
+	width:100%;
+}
+
+.graph .bar{
+	display:block;
+	background:#B1D632;
+	text-align:center;
+	color:#333;
+}
+
+.graph .bar span{
+	left:1em;
+}

static/fileuploader.js

         if (loaded != total) {
 			text = Math.round(loaded / total * 100);
 		}
-		$("#control_"+id).html(text+'% <img border="0" src="/static/loading.gif">')
+		$("#control_"+id).html('<div class="graph"><strong class="bar" style="width: '+text+'%;"><span>'+text+'%</span></strong> </div>')
     },
     _onComplete: function(id, fileName, result){
         qq.FileUploaderBasic.prototype._onComplete.apply(this, arguments);

themes/admin/upload-html5.html

             element: $("#file-uploader")[0],
             action: '/a/upload5/',
             allowedExtensions: ['jpg','jpeg','png','gif'],
-            sizeLimit:1024*1024,
+            sizeLimit:10000000,
             minSizeLimit:1,
+			maxConnections:1,
             onSubmit: function(id, fileName){},
         });     
 		

themes/admin/upload.html

 			'cancelImg':'/static/trash.png',
 			'multi' : true,
 			'queueID': 'img-upload-list',
-			'sizeLimit':1000000,
-			'fileDesc':'请选择图片*.jpg;*.gif;*.png;',
+			'sizeLimit':10000000,  //10M
+			'fileDesc':'请选择图片*.jpg;*.gif;*.png;*.jpeg',
 			'fileExt':'*.jpg;*.gif;*.png;*.jpge;',
 		});
 	   $("#img-upload-btn").click(function(){