0
votes

I have a problem regarding multiple image cropper, at first I've replaced the default File upload property with an Image cropper property on my Image media type. And I'm using multiple media picker to upload more than one images, my problem is how to get the image URL in the surface controller?

This is what I have done

var docsId = Umbraco.TypedContent(Convert.ToInt32(document.Get("id"))); var imageList = docsId.GetPropertyValue<string>("images").GetCropUrl(width: 329, height: 200);

but it says 'Cannnot implicitly convert type 'string' to 'System.Collections.Generic.List'

I tried another option, and I tried this code

var docsId = Umbraco.TypedContent(Convert.ToInt32(document.Get("id"))); var imageList = docsId.GetPropertyValue<string>("images").GetCropUrl(width: 329, height: 200);

its error again 'An exception of type 'System.ArgumentNullException' occurred in umbraco.dll but was not handled in user code'

Hope anyone can help with this problem. I'm new in Umbraco.

Thank you,

Jin

3
What's the difference between the two posted pieces of code?harvzor
And what type is document? IPublishedContent?harvzor
@Harvey, Thank you for your prompt replyJin
document is just the as GetPropertyValue.Jin
What version of Umbraco are you using?harvzor

3 Answers

0
votes

@Harvey - This is the document

var searcher = new IndexSearcher(indexDirectory, true);

var masterQuery = new BooleanQuery();

TopDocs resp = searcher.Search(masterQuery, null, searcher.MaxDoc());

foreach (var scoreDoc in resp.ScoreDocs) {
    var document = searcher.Doc(scoreDoc.doc);
    var docsId = Umbraco.TypedContent(Convert.ToInt32(document.Get("id")));
    var imageList = docsId.GetPropertyValue<string>("images").GetCropUrl(width: 329, height: 200);
}
0
votes

.GetCropUrl expects type System.Collections.Generic.List but you are trying to use type string.

Change your code to the following:

var docsId = Umbraco.TypedContent(Convert.ToInt32(document.Get("id")));
var imageList = Url.GetCropUrl(docsId, propertyAlias: "images", height: 200, width: 329);

Read up on using the image cropper here.

0
votes

I assume document is an Umbraco content node. And this document has a multiple media picker with the alias images

So you already got the document of Type IPublishedContent:

var document = Umbraco.TypedContent(Convert.ToInt32(document.Get("id")));

The multiple media picker stores the IDs of your picked medias comma seperated: 1124, 1130, 1401, ..., so first you need to get the IDs into an array:

var imageIds = docsId.GetPropertyValue<string>("images").Split(',');

Then you get a List of Medias from the IDs array:

var imageList = Umbraco.TypedMedia(imageIds);

Then you can get the url of the cropped image of each image as example with a for loop:

for (var image in imageList) 
{
    var imageCropUrl = image.GetCropUrl(width: 329, height: 200);
    <img src="imageCropUrl"></img>
}