def handle_upload(self): request = self.request try: folder_id = int(request.REQUEST.get("folder_id", 0)) if folder_id != 0: folder = Folder.objects.get(pk=folder_id) else: folder = None # Root folder upload. How bold! except Exception as exc: return JsonResponse({"error": "Invalid folder: %s" % force_text(exc)}) try: upload_file = request.FILES["file"] if upload_file.content_type.startswith("image/"): filer_file = filer_image_from_upload(request, path=folder, upload_data=upload_file) else: filer_file = filer_file_from_upload(request, path=folder, upload_data=upload_file) except Exception as exc: return JsonResponse({"error": force_text(exc)}) return JsonResponse({ "file": _filer_file_to_json_dict(filer_file), "message": _("%(file)s uploaded to %(folder)s") % { "file": filer_file.label, "folder": get_folder_name(folder) } })
def handle_upload(self): request = self.request try: folder_id = int(request.REQUEST["folder_id"]) if folder_id != 0: folder = Folder.objects.get(pk=folder_id) else: folder = None # Root folder upload. How bold! upload_file = request.FILES["file"] if upload_file.content_type.startswith("image/"): filer_file = filer_image_from_upload(request, path=folder, upload_data=upload_file) else: filer_file = filer_file_from_upload(request, path=folder, upload_data=upload_file) except Exception as exc: return JsonResponse({"message": force_text(exc)}) return JsonResponse({ "file": _filer_file_to_json_dict(filer_file), "message": _("%(file)s uploaded to %(folder)s") % { "file": filer_file.label, "folder": get_folder_name(folder) } })
def handle_upload(self): request = self.request folder_id = int(request.REQUEST["folder_id"]) folder = Folder.objects.get(pk=folder_id) upload_file = handle_filedrop_upload(request) try: if upload_file.content_type.startswith("image/"): filer_file = filer_image_from_upload(request, path=folder, upload_data=upload_file) else: filer_file = filer_file_from_upload(request, path=folder, upload_data=upload_file) except Exception as exc: return JsonResponse({"error": force_text(exc)}) return JsonResponse({"file": _filer_file_to_json_dict(filer_file)})