def METHOD_NAME(self, params):
    with transaction.atomic():
        qs = Media.objects.select_for_update().filter(pk=params["id"])
        if qs.count() != 1:
            raise Http404
        media_files = qs[0].media_files
        role = params["role"]
        body = params["body"]
        index = params["index"]
        if not media_files:
            raise Http404
        if role not in media_files:
            raise Http404
        if index >= len(media_files[role]):
            raise ValueError(
                f"Supplied index {index} is larger than current array size "
                f"{len(media_files[role])}"
            )
        old_path = media_files[role][index]["path"]
        new_path = body["path"]
        check_resource_prefix(new_path, qs[0])
        media_files[role][index] = body
        qs.update(media_files=media_files)
    media = Media.objects.get(pk=params["id"])
    if old_path != new_path:
        drop_media_from_resource(old_path, media)
        safe_delete(old_path, media.project.id)
        Resource.add_resource(new_path, media)
    return {"message": f"Media file in media object {media.id} successfully updated!"}