Ejemplo n.º 1
0
def upload_success(request):
    """所有分片上传成功"""
    name = request.POST.get('name')
    chunk = 0
    try:
        r = get_redis_conn()
    except:
        print('DatabaseError')
    with open("./apps/web/upload/%s" % name, 'wb') as target_file:  # 创建新文件
        while True:
            try:
                key = '%s%s' % (name, chunk)
                data = r.get(key)
                if data:
                    target_file.write(data)  # 读取分片内容写入新文件
                else:
                    break
                r.delete(key)
            except Exception as e:
                print(e, 222)
                break
            chunk += 1
        target_file.close()
        list_key = "%s_list" % name
        r.delete(list_key)
    return ajax.ajax_data(name)
Ejemplo n.º 2
0
def upload_success(request):
    """所有分片上传成功"""

    print("所有分片上传成功")

    task = request.POST.get('task_id')
    print("所有分片", task)
    ext = request.POST.get('ext', '')
    print('ext:', ext)
    upload_type = request.POST.get('type')
    print('upload_type:', upload_type)
    name = request.POST.get('name')
    print('name:', name)
    if len(ext) == 0 and upload_type:
        ext = upload_type.split('/')[1]
    chunk = 0
    with open("./media/file/%s" % name, 'wb') as target_file:  # 创建新文件
        while True:
            try:
                filename = './media/file/%s%s' % (task, chunk)
                source_file = open(filename, 'rb')  # 按序打开每个分片
                target_file.write(source_file.read())  # 读取分片内容写入新文件
                source_file.close()
                os.remove(filename)  # 删除该分片,节约空间
            except Exception as e:
                #找不到碎片文件跳出循环
                print(e, 222)
                break
            chunk += 1
        target_file.close()

        # 系统当前时间年份
        year = time.strftime('%Y')
        # 月份
        month = time.strftime('%m')
        # 日期
        day = time.strftime('%d')
        # 具体时间 小时分钟毫秒
        mdhms = time.strftime('%m%d%H%M%S')
        print("年", year)
        mymovefile(
            "./media/file/%s" % name, "./media/file/" + year + "/" + month +
            "/" + day + "/" + mdhms + "/%s" % name)

        # 把路径储存入数据库中
        models.Document.objects.create(docfile="/media/file/" + year + "/" +
                                       month + "/" + day + "/" + mdhms +
                                       "/%s" % name,
                                       filename=str(name))

        return HttpResponse("上传成功")

    return ajax.ajax_data(name)
Ejemplo n.º 3
0
def file_exist(request):
    """判断文件知否存在"""
    filename = request.POST.get('filename')
    key = "%s_list" % filename
    data = {}
    filename = "./apps/web/upload/%s" % filename
    if os.path.exists(filename):
        data['flag_exist'] = True
        data['file_path'] = filename
    else:
        data['flag_exist'] = False

    list_tmp = []
    r = get_redis_conn()
    list_data = r.get(key)
    if list_data:
        list_tmp = eval(list_data)
        list_tmp = list(set([int(i) for i in list_tmp]))
    data['list'] = list_tmp
    return ajax.ajax_data(data)
Ejemplo n.º 4
0
def list_exist(request):
    """判断该文件上传了多少个分片"""
    name = request.POST.get('filename')
    chunk = 0
    data = {}
    filename = "./file/%s" % name
    if os.path.exists(filename):
        data['flag_exist'] = True
        data['file_path'] = filename
    else:
        data['flag_exist'] = False
    list = []
    while True:
        if os.path.exists("./file/%s%s" % (name, chunk)):
            list.append(chunk)
        else:
            break
        chunk += 1
    data['list'] = list
    return ajax.ajax_data(data)
Ejemplo n.º 5
0
def p_api(request):
    data = {}
    for i in range(6):
        data[i] = i * i
    return ajax.ajax_data(data)
Ejemplo n.º 6
0
        ext = upload_type.split('/')[1]
    chunk = 0
    with open("./file/%s" % name, 'wb') as target_file:  # 创建新文件
        while True:
            try:
                filename = './file/%s%s' % (name, chunk)
                source_file = open(filename, 'rb')  # 按序打开每个分片
                target_file.write(source_file.read())  # 读取分片内容写入新文件
                source_file.close()
                # os.remove(filename)  # 删除该分片,节约空间
            except Exception, e:
                print e, 222
                break
            chunk += 1
        target_file.close()
    return ajax.ajax_data(name)


def list_exist(request):
    """判断该文件上传了多少个分片"""
    name = request.POST.get('filename')
    chunk = 0
    data = {}
    filename = "./file/%s" % name
    if os.path.exists(filename):
        data['flag_exist'] = True
        data['file_path'] = filename
    else:
        data['flag_exist'] = False
    list = []
    while True: