示例#1
0
def delete(request, callback, *args, **kwargs):
    uuid = kwargs.get('qquuid', '')
    if uuid:
        try:
            callback(uuid=uuid)
        except CallbackError as e:
            return make_response(status=400,
                                 content=json.dumps({
                                     'success': False,
                                     'error': '%s' % repr(e)
                                 }))
        except Exception as e:
            return make_response(status=500,
                                 content=json.dumps({
                                     'success':
                                     False,
                                     'error':
                                     'Exception thrown by callback'
                                 }))
        return make_response(content=json.dumps({'success': True}))
    return make_response(status=404,
                         content=json.dumps({
                             'success': False,
                             'error': 'File not present'
                         }))
示例#2
0
def post(request, callback):
    form = UploadFileForm(request.POST, request.FILES)
    if form.is_valid():
        file_attrs = form.cleaned_data
        dest_path = os.path.join(settings.UPLOAD_DIRECTORY,
                                 file_attrs['qquuid'])
        dest_file = os.path.join(dest_path, file_attrs['qqfilename'])
        chunk = False
        if file_attrs['qqtotalparts'] is not None and int(
                file_attrs['qqtotalparts']) > 1:
            dest_file = os.path.join(dest_file + '.chunks',
                                     str(file_attrs['qqpartindex']))
            chunk = True

        utils.save_upload(file_attrs['qqfile'], dest_file)

        if chunk and (file_attrs['qqtotalparts'] - 1
                      == file_attrs['qqpartindex']):
            dest_file = os.path.join(dest_path, file_attrs['qqfilename'])
            utils.combine_chunks(file_attrs['qqtotalparts'],
                                 file_attrs['qqtotalfilesize'],
                                 source_folder=dest_file + '.chunks',
                                 dest=dest_file)
            shutil.rmtree(dest_file + '.chunks')
            chunk = False

        if not chunk:
            try:
                callback(file_path=dest_file, uuid=file_attrs['qquuid'])
            except CallbackError as e:
                return make_response(status=400,
                                     content=json.dumps({
                                         'success': False,
                                         'error': '%s' % repr(e)
                                     }))
            except Exception as e:
                return make_response(status=500,
                                     content=json.dumps({
                                         'success':
                                         False,
                                         'error':
                                         'Exception thrown by callback'
                                     }))
            finally:
                shutil.rmtree(dest_path)

        return make_response(content=json.dumps({'success': True}))
    else:
        return make_response(status=400,
                             content=json.dumps({
                                 'success':
                                 False,
                                 'error':
                                 '%s' % repr(form.errors)
                             }))
示例#3
0
def delete(request, callback, *args, **kwargs):
    uuid = kwargs.get('qquuid', '')
    if uuid:
        try:
            callback(uuid=uuid)
        except CallbackError, e:
            return make_response(status=400,
                content=json.dumps({
                    'success': False,
                    'error': '%s' % repr(e)
                }))
        except Exception, e:
            return make_response(status=500,
                content=json.dumps({
                    'success': False,
                    'error': 'Exception thrown by callback'
                }))
示例#4
0
def post(request, callback):
    form = UploadFileForm(request.POST, request.FILES)
    if form.is_valid():
        file_attrs = form.cleaned_data
        dest_path = os.path.join(settings.UPLOAD_DIRECTORY, file_attrs['qquuid'])
        dest_file = os.path.join(dest_path, file_attrs['qqfilename'])
        chunk = False
        if file_attrs['qqtotalparts'] != None and int(file_attrs['qqtotalparts']) > 1:
            dest_file = os.path.join(dest_file+'.chunks', str(file_attrs['qqpartindex']))
            chunk = True

        utils.save_upload(file_attrs['qqfile'], dest_file)

        if chunk and (file_attrs['qqtotalparts'] - 1 == file_attrs['qqpartindex']):
            dest_file = os.path.join(dest_path, file_attrs['qqfilename'])
            utils.combine_chunks(file_attrs['qqtotalparts'], file_attrs['qqtotalfilesize'],
                source_folder=dest_file+'.chunks', dest=dest_file)
            shutil.rmtree(dest_file+'.chunks')
            chunk = False

        if not chunk:
            try:
                callback(file_path=dest_file, uuid=file_attrs['qquuid'])
            except CallbackError, e:
                return make_response(status=400,
                    content=json.dumps({
                        'success': False,
                        'error': '%s' % repr(e)
                    }))
            except Exception, e:
                return make_response(status=500,
                    content=json.dumps({
                        'success': False,
                        'error': 'Exception thrown by callback'
                    }))
            finally:
示例#5
0
            except CallbackError, e:
                return make_response(status=400,
                    content=json.dumps({
                        'success': False,
                        'error': '%s' % repr(e)
                    }))
            except Exception, e:
                return make_response(status=500,
                    content=json.dumps({
                        'success': False,
                        'error': 'Exception thrown by callback'
                    }))
            finally:
                shutil.rmtree(dest_path)

        return make_response(content=json.dumps({ 'success': True }))
    else:
        return make_response(status=400,
            content=json.dumps({
                'success': False,
                'error': '%s' % repr(form.errors)
            }))

def delete(request, callback, *args, **kwargs):
    uuid = kwargs.get('qquuid', '')
    if uuid:
        try:
            callback(uuid=uuid)
        except CallbackError, e:
            return make_response(status=400,
                content=json.dumps({