方法 'SetValue' 没有重载在 Umbraco 9 中接受 7 个参数

No overload for method 'SetValue' takes 7 arguments in Umbraco 9

我正在尝试下载远程图像并将其存储为本地媒体,作为定期托管服务的一部分(请参阅 here)。我正在按照 Umbraco 9.0 的示例从流创建媒体项目:

https://our.umbraco.com/documentation/reference/management/services/mediaservice/#creating-a-new-media-item-from-a-stream

我的方法是这样的:

        private void ConvertImageToLocalImage(string remoteImageUrl, string title)
        {

            var downloadFolder = $"{_hostingEnvironment.ContentRootPath}\App_Data\TEMP\Images";

            var fileName = Path.GetFileName(remoteImageUrl.Split('?')[0]);

            var fileExt = Path.GetExtension(fileName);

            var downloadPath = $"{downloadFolder}\{title.Replace(" ", "_")}{fileExt}";

            if (Directory.Exists(downloadFolder) == false)
            {
                Directory.CreateDirectory(downloadFolder);
            }

            using (var client = new WebClient())

            client.DownloadFile(remoteImageUrl, downloadPath);

            using FileStream stream = System.IO.File.OpenRead(downloadPath);

            IMedia media = _mediaService.CreateMedia(title, -1, Constants.Conventions.MediaTypes.Image);

            media.SetValue(_mediaFileManager, _shortStringHelper, _contentTypeBaseServiceProvider, _serializer, Constants.Conventions.MediaTypes.File, fileName, stream);

            _mediaService.Save(media);
        }

但是,我收到错误消息:

方法 'SetValue' 没有重载需要 7 个参数

我似乎可以访问的唯一 'SetValue' 方法是:

void SetValue(string propertyTypeAlias, object value, string culture = null, string segment = null);

我不确定我做错了什么...

我在文件顶部有以下 using 语句:

using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Infrastructure.HostedServices;

解决了...

我需要包括:

using Umbraco.Extensions;

然后重载方法的签名实际上与文档所说的完全不同,这是方法的签名:

void SetValue(this IContentBase content, MediaFileManager mediaFileManager, MediaUrlGeneratorCollection mediaUrlGenerators, IShortStringHelper shortStringHelper, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, string propertyTypeAlias, string filename, Stream filestream, string culture = null, string segment = null)

最终看起来像这样:

media.SetValue(_mediaFileManager, _mediaUrlGenerators, _shortStringHelper, _contentTypeBaseServiceProvider, "umbracoFile", fileName, stream)