Kentico 图片 API - 需要 return 图片 URL 而不是 ASP.NET Web API 中的 Guid
Kentico image API - Need to return image URL instead of Guid in ASP.NET Web API
这是我在Whosebug上的第一个问题,如果标题或问题不好请见谅。
此刻我得到了 VoucherResponse class
public class VoucherResponse
{
public int VoucherID { get; set; }
public string VoucherTitle { get; set; }
public IEnumerable<VoucherVariant> VoucherVariants { get; set; }
public string[] VoucherImages { get; set; }
}
和网络api方法
return Ok(from v in distinctby
select new VoucherResponse
{
VoucherID = v.VoucherID,
VoucherTitle = v.VoucherTitle,
VoucherVariants = (from voucher in voucherToLookup[v.VoucherID]
select new VoucherVariant
{
VoucherDiscountedPrice = voucher.VoucherPrice - (voucher.VoucherPrice * voucher.VoucherDiscount/ 100),
VoucherVariantId = voucher.VoucherVariantId,
VoucherPrice = voucher.VoucherPrice,
VoucherStock = 1
}),
VoucherImages = (from image in distinctby
where v.VoucherID == image.VoucherID
select image.VoucherImages
// URLHelper.GetAbsoluteUrl(ModuleCommands.MediaLibraryGetMediaFileUrl(image.FileGUID, voucher.NodeAlias + "_" + image.ImageOrder))).ToArray(),
).ToArray()
});
目前我正在获取结果
{
"voucherID": 380,
"voucherTitle": "Woolworths e-Gift Card",
"voucherVariants": [
{
"voucherVariantId": 397,
"voucherPrice": 100,
"voucherDiscountedPrice": 95,
"voucherStock": 1
},
{
"voucherVariantId": 389,
"voucherPrice": 200,
"voucherDiscountedPrice": 190,
"voucherStock": 1
},
{
"voucherVariantId": 393,
"voucherPrice": 300,
"voucherDiscountedPrice": 285,
"voucherStock": 1
},
{
"voucherVariantId": 394,
"voucherPrice": 400,
"voucherDiscountedPrice": 380,
"voucherStock": 1
},
{
"voucherVariantId": 395,
"voucherPrice": 500,
"voucherDiscountedPrice": 475,
"voucherStock": 1
}
],
"voucherImages": [
" B4A3A070-3ED1-4086-8B33-21465AA58C7A, 2FB01963-2D71-4C79-9EE8-38A114CAF1A6"
]
我需要return这样的代金券图片
"VoucherImages" : [
{"www.kentico.info/imageOne.jpg"}
{"www.kentico.info/imageTwo.jpg"}
]
首先感谢你试图帮助我。
我自己解决了这个问题。
@rocky 图像存储在媒体库中,我创建了可以正常工作的方法,但我仍然得到 "ugly url" 之类的
“http://localhost:50848/getmedia/8f5f2e87-782c-4ee2-b6c0-dba614588fe4/
我想得到类似“http://localhost:50848/getmedia/image1.jpg
但是会对此进行研究,如果有人需要功能中的代码,我会在下面粘贴方法
private string[] GetImageURLs(string guids, string voucherTitle)
{
List<string> result = new List<string>();
string[] guid = guids.Split(',');
string alias, url,image;
foreach (var item in guid)
{
url = ModuleCommands.MediaLibraryGetMediaFileUrl(ValidationHelper.GetGuid(item, Guid.Empty), SiteContext.CurrentSiteName);
image = URLHelper.GetAbsoluteUrl(url);
result.Add(image);
}
return result.ToArray();
}
这是我在Whosebug上的第一个问题,如果标题或问题不好请见谅。
此刻我得到了 VoucherResponse class
public class VoucherResponse
{
public int VoucherID { get; set; }
public string VoucherTitle { get; set; }
public IEnumerable<VoucherVariant> VoucherVariants { get; set; }
public string[] VoucherImages { get; set; }
}
和网络api方法
return Ok(from v in distinctby
select new VoucherResponse
{
VoucherID = v.VoucherID,
VoucherTitle = v.VoucherTitle,
VoucherVariants = (from voucher in voucherToLookup[v.VoucherID]
select new VoucherVariant
{
VoucherDiscountedPrice = voucher.VoucherPrice - (voucher.VoucherPrice * voucher.VoucherDiscount/ 100),
VoucherVariantId = voucher.VoucherVariantId,
VoucherPrice = voucher.VoucherPrice,
VoucherStock = 1
}),
VoucherImages = (from image in distinctby
where v.VoucherID == image.VoucherID
select image.VoucherImages
// URLHelper.GetAbsoluteUrl(ModuleCommands.MediaLibraryGetMediaFileUrl(image.FileGUID, voucher.NodeAlias + "_" + image.ImageOrder))).ToArray(),
).ToArray()
});
目前我正在获取结果
{
"voucherID": 380,
"voucherTitle": "Woolworths e-Gift Card",
"voucherVariants": [
{
"voucherVariantId": 397,
"voucherPrice": 100,
"voucherDiscountedPrice": 95,
"voucherStock": 1
},
{
"voucherVariantId": 389,
"voucherPrice": 200,
"voucherDiscountedPrice": 190,
"voucherStock": 1
},
{
"voucherVariantId": 393,
"voucherPrice": 300,
"voucherDiscountedPrice": 285,
"voucherStock": 1
},
{
"voucherVariantId": 394,
"voucherPrice": 400,
"voucherDiscountedPrice": 380,
"voucherStock": 1
},
{
"voucherVariantId": 395,
"voucherPrice": 500,
"voucherDiscountedPrice": 475,
"voucherStock": 1
}
],
"voucherImages": [
" B4A3A070-3ED1-4086-8B33-21465AA58C7A, 2FB01963-2D71-4C79-9EE8-38A114CAF1A6"
]
我需要return这样的代金券图片
"VoucherImages" : [
{"www.kentico.info/imageOne.jpg"}
{"www.kentico.info/imageTwo.jpg"}
]
首先感谢你试图帮助我。 我自己解决了这个问题。 @rocky 图像存储在媒体库中,我创建了可以正常工作的方法,但我仍然得到 "ugly url" 之类的 “http://localhost:50848/getmedia/8f5f2e87-782c-4ee2-b6c0-dba614588fe4/ 我想得到类似“http://localhost:50848/getmedia/image1.jpg 但是会对此进行研究,如果有人需要功能中的代码,我会在下面粘贴方法
private string[] GetImageURLs(string guids, string voucherTitle)
{
List<string> result = new List<string>();
string[] guid = guids.Split(',');
string alias, url,image;
foreach (var item in guid)
{
url = ModuleCommands.MediaLibraryGetMediaFileUrl(ValidationHelper.GetGuid(item, Guid.Empty), SiteContext.CurrentSiteName);
image = URLHelper.GetAbsoluteUrl(url);
result.Add(image);
}
return result.ToArray();
}