Image upload gives "Uncaught Unknown file table name: " error when trying to display or render.

Image upload gives "Uncaught Unknown file table name: " error when trying to display or render.

bsdatatablebsdatatable Posts: 1Questions: 1Answers: 0
edited April 2018 in Free community support

server side

 public IHttpActionResult Rest(HttpRequest request)
        {

            using (var stdb = new DataTables.Database("sqlserver", db.Database.Connection.ConnectionString))
            {
                var response = new Editor(stdb, "xyz", "xyzid")
                .Model<xyz>()
                .Field(new Field("xyzId").Set(false))
                .Field(new Field("Field1").Validator(Validation.NotEmpty()))
                .TryCatch(false)
                .Field(new Field("SwtaId")
                .SetFormatter(Format.IfEmpty(null))
                         .Upload(
                                    new Upload((file, id) =>
                                    {
                                        fileName = file.FileName;
                                        using (Stream uploadStream = file.InputStream)
                                        {
                                            container.CreateIfNotExists(BlobContainerPublicAccessType.Blob);
                                            var blockBlob = container.GetBlockBlobReference(fileName);
                                            blockBlob.UploadFromStream(uploadStream);
                                            urlForClient = ConfigurationManager.AppSettings["AzureStorageUrl"] + containerName + "//" + fileName;
                                        }
                                    return id;

                                   }) 

                            //.Upload(new Upload(urlForClient + @"uploads\__ID____EXTN__")
                            .Db("xyzAttachment", "xyzaId", new Dictionary<string, object>
                            {
                                {"AttachmentPath", urlForClient},
                                {"FileName", Upload.DbType.FileName},
                                {"FileSize", Upload.DbType.FileSize}
                            })
                      )
                    )

                .Process(request)
                .Data();
                return Json(response);
            }
        }

client:

 editor = new $.fn.dataTable.Editor({
                ajax: {
                    create: {
                        type: 'POST',
                        url: createApiUrl,
                        headers: authHeaders
                    },
                    edit: {
                        type: 'PUT',
                        url: editApiUrl,
                        headers: authHeaders
                    },
                    remove: {
                        type: 'DELETE',
                        url: deleteApiUrl,
                        headers: authHeaders
                    }
                },
                table: "#Table",
                idSrc: "xyzId",
                fields: [
{
                        label: "Field1:",
                        name: "field1",
                                        },
 {
                    label: "Image:",
                    name: "xyzaId",
                    type: "upload",
                    ajax: {
                        type: "POST",
                        url: uploadApiUrl,
                        headers: authHeaders,
                        done: function (json) {
                                     console.log(json);
                        }
                    },
                    display: function (Id) {
                         var path = editor.file('xyzAttachment', Id).AttachmentPath;
                        var filepath = path + "/" + editor.file('xyzAttachment', Id).FileName
                        return '<img src="' + filepath + '"/>';
                    },
                    clearText: "Clear",
                    noImageText: 'No image'
                }
table = $('#Table').DataTable({
                dom: "Bfrtip",
                ajax: {
                    url: getApiUrl,
                   headers: authHeaders,
                    dataSrc:''
                },
                "bDestroy": true,
                "iDisplayLength": 3,
                columns: [
                    { data: Field1}
 {
                        data: "SwtaId",
                        render: function (Id) {
                  
                            return '<img src="' + editor.file('xyzAttachment', xyzaId).AttachmentPath + "/" + editor.file('xyzAttachment', xyzaId).FileName +'"/>';
                            },
                        defaultContent: "No image",
                        title: "Image"
                    }
                ],

any help is appreciated.

This discussion has been closed.