def METHOD_NAME(request):
    # add irods file into an existing resource
    res_id = request.POST.get('res_id', '')
    resource, _, _ = authorize(request, res_id, needed_permission=ACTION_TO_AUTHORIZE.EDIT_RESOURCE)
    res_files = request.FILES.getlist('files')
    extract_metadata = request.POST.get('extract-metadata', 'No')
    extract_metadata = True if extract_metadata.lower() == 'yes' else False
    irods_fnames = request.POST.get('upload', '')
    irods_fnames_list = irods_fnames.split(',')
    res_cls = resource.__class__
    # TODO: read resource type from resource, not from input file
    valid, ext = check_upload_files(res_cls, irods_fnames_list)
    source_names = []
    if not valid:
        return JsonResponse({'error': "Invalid file type: {ext}".format(ext=ext)},
                            status=status.HTTP_400_BAD_REQUEST)
    else:
        homepath = irods_fnames_list[0]
        # TODO: this should happen whether resource is federated or not
        irods_federated = utils.is_federated(homepath)
        if irods_federated:
            source_names = irods_fnames.split(',')
        else:
            user = request.POST.get('irods_username')
            password = request.POST.get("irods_password")
            port = request.POST.get("irods_port")
            host = request.POST.get("irods_host")
            zone = request.POST.get("irods_zone")
            try:
                upload_from_irods(username=user, password=password, host=host, port=port,
                                  zone=zone, irods_fnames=irods_fnames, res_files=res_files)
            except SessionException as ex:
                return JsonResponse(
                    {"error": ex.stderr}, status=status.HTTP_500_INTERNAL_SERVER_ERROR
                )
    try:
        utils.resource_file_add_pre_process(resource=resource, files=res_files, user=request.user,
                                            extract_metadata=extract_metadata,
                                            source_names=source_names, folder='')
    except hydroshare.utils.ResourceFileSizeException as ex:
        return JsonResponse({'error': str(ex)}, status=status.HTTP_400_BAD_REQUEST)
    except (hydroshare.utils.ResourceFileValidationException, Exception) as ex:
        return JsonResponse({'error': str(ex)}, status=status.HTTP_400_BAD_REQUEST)
    try:
        hydroshare.utils.resource_file_add_process(resource=resource, files=res_files,
                                                   user=request.user,
                                                   extract_metadata=extract_metadata,
                                                   source_names=source_names, folder='')
    except (hydroshare.utils.ResourceFileValidationException, SessionException) as ex:
        if str(ex):
            return JsonResponse({'error': str(ex)},
                                status=status.HTTP_500_INTERNAL_SERVER_ERROR)
        elif ex.stderr:
            return JsonResponse({'error': ex.stderr},
                                status=status.HTTP_500_INTERNAL_SERVER_ERROR)
    return JsonResponse({}, status=status.HTTP_200_OK)