Exemple #1
0
 def post(self, request, *args, **kwargs):
     """A POST request. Validate the form and then handle the upload
     based ont the POSTed data. Does not handle extra parameters yet.
     """
     form = UploadFileForm(request.POST, request.FILES)
     if form.is_valid():
         handle_upload(request.FILES["qqfile"], form.cleaned_data)
         return make_response(content=json.dumps({"success": True}))
     else:
         return make_response(status=400, content=json.dumps({"success": False, "error": "%s" % repr(form.errors)}))
Exemple #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)
                             }))
Exemple #3
0
 def post(self, request, *args, **kwargs):
     """A POST request. Validate the form and then handle the upload
     based ont the POSTed data. Does not handle extra parameters yet.
     """
     form = UploadFileForm(request.POST, request.FILES)
     if form.is_valid():
         handle_upload(request.FILES['qqfile'], form.cleaned_data)
         return make_response(content=json.dumps({'success': True}))
     else:
         return make_response(status=400,
                              content=json.dumps({
                                  'success':
                                  False,
                                  'error':
                                  '%s' % repr(form.errors)
                              }))
Exemple #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: