Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indexing errors when switching the upload field for media to a cropper #7

Open
Shazwazza opened this issue Dec 2, 2014 · 5 comments

Comments

@Shazwazza
Copy link

It's because of this code here:

        // Extract the filename from media items
        if(e.Fields.ContainsKey("umbracoFile"))
        {
            e.Fields["umbracoFileName"] = Path.GetFileName(e.Fields["umbracoFile"]);
        }

in the ezSearchBoostrapper class

If you change the file upload on a media item to be a cropper, then the umbracoFile value is Json and this throws a ysod.

@akeilox
Copy link

akeilox commented Dec 2, 2014

have you find a workaround Shannon, doing media ezsearch with file upload replaced as cropper?

@Shazwazza
Copy link
Author

I haven't tried anything, if ezsearch get's updated that would be the best fix, would be pretty simple really.

Otherwise you can try to add your own indexing handler just like ez search does and parse the value properly.

@akeilox
Copy link

akeilox commented Dec 2, 2014

any pointers or quick fix you can share for changing the part to support cropper default data type? I am not sure how to update to code to support the json parsing accordingly...

// Extract the filename from media items
if(e.Fields.ContainsKey("umbracoFile"))
{
e.Fields["umbracoFileName"] = Path.GetFileName(e.Fields["umbracoFile"]);
}

@garpunkal
Copy link

garpunkal commented Dec 28, 2016

This will support the imagecropdataset... not sure if there is any other way to detect if JSON exists rather than the URL.

if (e.Fields.ContainsKey(StaticValues.Properties.UmbracoFile))
{
try
{
var imageCrop = JsonConvert.DeserializeObject(e.Fields[StaticValues.Properties.UmbracoFile]);
e.Fields[StaticValues.Properties.UmbracoFileName] = Path.GetFileName(imageCrop.Src);
}
catch
{
e.Fields[StaticValues.Properties.UmbracoFileName] = Path.GetFileName(e.Fields[StaticValues.Properties.UmbracoFile]);
}
}

@TwoMoreThings
Copy link

This may be considered a bit hacky, but a quick fix would be to extract the filename using regex

if (e.Fields.ContainsKey("umbracoFile"))
{
var match = Regex.Match(e.Fields["umbracoFile"], @"(/media.*?.(jpg|png|gif|jpeg|svg))");
if (match.Success)
{
e.Fields["umbracoFileName"] = match.Value;
}
}

of course this depends on specific media types, and it doesn't check if the image cropper or upload field has been used

t

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants