I cannot retrieve related data to a photo upload

I cannot retrieve related data to a photo upload

NBBITNBBIT Posts: 2Questions: 1Answers: 0

I can add a photo to an existing record the photo field is updated with the child Key and the photo table has a new record added. All is good at that point.
However I cannot display the image in the editor with;
return '<img src="' + editor.file('photo', file_id).web_path + '"/>';

I have on the columns js ;
return file_id ?
'<img src="' + editor.file('photo', file_id).web_path + '"/>' :
null;
When I try to create a new record i get a "Input not valid on my first field when I click CREATE
The data table display tries to show image but has "undefined" for the src.

The file_id is being populated with the correct id in either case.

In my controller I have:

.Field(new Field("photo")
                        .SetFormatter(Format.IfEmpty(null))
                        .Upload(new Upload(request.PhysicalApplicationPath + @"web\uploads\__ID____EXTN__")
                            .Db("photo", "id", new Dictionary<string, object>
                            {
                                {"WebPath", Upload.DbType.WebPath},
                                {"SystemPath", Upload.DbType.SystemPath},
                                {"Filename", Upload.DbType.FileName}
                              
                            })
                            .DbClean(data =>
                             {
                                 foreach (var row in data)
                                 {
                                     // Do something;
                                 }
                                 return true;
                            })
                            .Validator(Validation.FileSize(500000, "Max file size is 500K."))
                            .Validator(Validation.FileExtensions(new[] { "jpg", "png", "gif" }, "Please upload an image."))
                        )
                    )

And my JS is:

{
                    label: "Photo:",
                    name: "photo",
                    type: "upload",
                    display: function (file_id) {
                        return '<img src="' + editor.file('photo', file_id).web_path + '"/>';
                    },
                    clearText: "Clear",
                    noImageText: 'No image'
                }

And:

    {
                    "data": "photo",
                    render: function (file_id) {
                        return file_id ?
                            '<img src="' + editor.file('photo', file_id).web_path + '"/>' :
                            null;
                    },
                    defaultContent: "No image",
                    title: "Image"

                }

Answers

  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin

    Hi,

    Looks like you need to use WebPath rather than web_path from your db configuration - i.e.:

    editor.file('photo', file_id).WebPath
    

    That said, you note the value is null, I would have expected undefined for that issue.

    Can you show me the JSON being returned by the server when you load the table please?

    Thanks,
    Allan

  • NBBITNBBIT Posts: 2Questions: 1Answers: 0

    Just hate it when you look and look and look and still can't see that little bugger. Thanks a lot allan

This discussion has been closed.