• 大小: 13.76M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-25
  • 语言: 其他
  • 标签: 其他  

资源简介

iBarn-master.zip

资源截图

代码片段和文件信息

# -*- coding: utf-8 -*-
#
# jQuery File Upload Plugin GAE Python Example 2.0
# https://github.com/blueimp/jQuery-File-Upload
#
# Copyright 2011 Sebastian Tschan
# https://blueimp.net
#
# Licensed under the MIT license:
# http://www.opensource.org/licenses/MIT
#

from __future__ import with_statement
from google.appengine.api import files images
from google.appengine.ext import blobstore deferred
from google.appengine.ext.webapp import blobstore_handlers
import json re urllib webapp2

WEBSITE = ‘http://blueimp.github.com/jQuery-File-Upload/‘
MIN_FILE_SIZE = 1 # bytes
MAX_FILE_SIZE = 5000000 # bytes
IMAGE_TYPES = re.compile(‘image/(gif|p?jpeg|(x-)?png)‘)
ACCEPT_FILE_TYPES = IMAGE_TYPES
THUMBNAIL_MODIFICATOR = ‘=s80‘ # max width / height
EXPIRATION_TIME = 300 # seconds

def cleanup(blob_keys):
    blobstore.delete(blob_keys)

class UploadHandler(webapp2.RequestHandler):

    def initialize(self request response):
        super(UploadHandler self).initialize(request response)
        self.response.headers[‘Access-Control-Allow-Origin‘] = ‘*‘
        self.response.headers[
            ‘Access-Control-Allow-Methods‘
        ] = ‘OPTIONS HEAD GET POST PUT DELETE‘
    
    def validate(self file):
        if file[‘size‘] < MIN_FILE_SIZE:
            file[‘error‘] = ‘File is too small‘
        elif file[‘size‘] > MAX_FILE_SIZE:
            file[‘error‘] = ‘File is too big‘
        elif not ACCEPT_FILE_TYPES.match(file[‘type‘]):
            file[‘error‘] = ‘Filetype not allowed‘
        else:
            return True
        return False
    
    def get_file_size(self file):
        file.seek(0 2) # Seek to the end of the file
        size = file.tell() # Get the position of EOF
        file.seek(0) # Reset the file position to the beginning
        return size
    
    def write_blob(self data info):
        blob = files.blobstore.create(
            mime_type=info[‘type‘]
            _blobinfo_uploaded_filename=info[‘name‘]
        )
        with files.open(blob ‘a‘) as f:
            f.write(data)
        files.finalize(blob)
        return files.blobstore.get_blob_key(blob)
    
    def handle_upload(self):
        results = []
        blob_keys = []
        for name fieldStorage in self.request.POST.items():
            if type(fieldStorage) is unicode:
                continue
            result = {}
            result[‘name‘] = re.sub(r‘^.*\\‘ ‘‘
                fieldStorage.filename)
            result[‘type‘] = fieldStorage.type
            result[‘size‘] = self.get_file_size(fieldStorage.file)
            if self.validate(result):
                blob_key = str(
                    self.write_blob(fieldStorage.value result)
                )
                blob_keys.append(blob_key)
                result[‘delete_type‘] = ‘DELETE‘
                result[‘delete_url‘] = self.request.host_url +\
                    ‘/?key=‘ + urllib.quote(blob_key ‘‘)
                if (IMAGE_TYPES.match(result[‘type‘])):
              

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-02-14 22:17  iBarn-master\
     目录           0  2017-12-28 18:50  iBarn-master\action\
     文件        5032  2017-12-28 18:50  iBarn-master\action\Collection.class.php
     文件       37868  2017-12-28 18:50  iBarn-master\action\Core.class.php
     文件        4610  2017-12-28 18:50  iBarn-master\action\Install.class.php
     文件       12852  2017-12-28 18:50  iBarn-master\action\Share.class.php
     文件        7697  2017-12-28 18:50  iBarn-master\action\User.class.php
     目录           0  2017-12-28 18:50  iBarn-master\conf\
     文件         171  2017-12-28 18:50  iBarn-master\conf\code.php
     文件        2957  2017-12-28 18:50  iBarn-master\conf\config.php
     文件         659  2017-12-28 18:50  iBarn-master\conf\filter.php
     目录           0  2017-12-28 18:50  iBarn-master\conf\lang\
     文件        5575  2017-12-28 18:50  iBarn-master\conf\lang\lang.php
     文件        4062  2017-12-28 18:50  iBarn-master\conf\lang\tipLang.php
     文件        3642  2017-12-28 18:50  iBarn-master\conf\mime.php
     文件         148  2017-12-28 18:50  iBarn-master\conf\upload.php
     目录           0  2017-12-28 18:50  iBarn-master\data\
     文件          73  2017-12-28 18:50  iBarn-master\data\.gitignore
     目录           0  2017-12-28 18:50  iBarn-master\html\
     文件        7056  2017-12-28 18:50  iBarn-master\html\avatar.php
     文件       12070  2017-12-28 18:50  iBarn-master\html\collection.php
     文件        1526  2017-12-28 18:50  iBarn-master\html\error.php
     文件         424  2017-12-28 18:50  iBarn-master\html\foot.php
     文件        9438  2017-12-28 18:50  iBarn-master\html\head.php
     文件       44169  2017-12-28 18:50  iBarn-master\html\index.php
     文件        6311  2017-12-28 18:50  iBarn-master\html\install.php
     文件        4808  2017-12-28 18:50  iBarn-master\html\login.php
     文件       15853  2017-12-28 18:50  iBarn-master\html\myshare.php
     文件       12678  2017-12-28 18:50  iBarn-master\html\offer.php
     文件       11823  2017-12-28 18:50  iBarn-master\html\own.php
     文件       11829  2017-12-28 18:50  iBarn-master\html\pay.php
............此处省略2309个文件信息

评论

共有 条评论