我想在nopcommerce数据库中保存图像URL。有人可以告诉我如何将图像的URL保存在NOPCOMMERCE数据库中吗? 此GetThumbUrl方法用于获取图像url,InsertPicture方法用于在数据库中插入没有图像路径的图像。
如何在InsertPicture方法中调用GetThumbUrl方法以将图像路径保存在数据库中?
public string GetThumbUrl(string thumbFileName, string storeLocation = null)
{
storeLocation = !String.IsNullOrEmpty(storeLocation)
? storeLocation
: _webHelper.GetStoreLocation();
var url = storeLocation + "content/images/thumbs/";
if (_mediaSettings.MultipleThumbDirectories)
{
//get the first two letters of the file name
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(thumbFileName);
if (fileNameWithoutExtension != null && fileNameWithoutExtension.Length > MULTIPLE_THUMB_DIRECTORIES_LENGTH)
{
var subDirectoryName = fileNameWithoutExtension.Substring(0, MULTIPLE_THUMB_DIRECTORIES_LENGTH);
url = url + subDirectoryName + "/";
}
}
url = url + thumbFileName;
return url;
}
public virtual Picture InsertPicture(byte[] pictureBinary, string mimeType, string seoFilename,
string altAttribute = null, string titleAttribute = null,
bool isNew = true, bool validateBinary = true)
{
int targetSize = 0;
PictureType defaultPictureType = PictureType.Entity;
string storeLocation = null;
mimeType = CommonHelper.EnsureNotNull(mimeType);
mimeType = CommonHelper.EnsureMaximumLength(mimeType, 20);
seoFilename = CommonHelper.EnsureMaximumLength(seoFilename, 100);
if (validateBinary)
pictureBinary = ValidatePicture(pictureBinary, mimeType);
var inspicture = new Picture
{
PictureBinary = this.StoreInDb ? pictureBinary : new byte[0],
MimeType = mimeType,
SeoFilename = seoFilename,
AltAttribute = altAttribute,
TitleAttribute = titleAttribute,
IsNew = isNew,
};
_pictureRepository.Insert(inspicture);
if (!this.StoreInDb)
SavePictureInFile(inspicture.Id, pictureBinary, mimeType);
//event notification
_eventPublisher.EntityInserted(inspicture);
return inspicture;
}