예제 #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({