Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Best solution to attach images to a record

Questions related to using nuBuilder Forte.
Post Reply
deckoff
Posts: 17
Joined: Tue Jul 10, 2018 12:34 pm
Been thanked: 1 time

Best solution to attach images to a record

Unread post by deckoff »

Hello
I am doing a simple dental database application, but I need some images (x-rays)attached to the database for each patient.
What would be the best way to store that - I need the file to be uploaded form the patients form, and be shown when needed. What would be the best solution to do this?
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Best solution to attach images to a record

Unread post by toms »

Hi,

If several files per patient have to be stored, a Subform (Type Grid) with an "Upload File" object might be suitable.

https://wiki.nubuilder.cloud/ ... .php/Files
deckoff
Posts: 17
Joined: Tue Jul 10, 2018 12:34 pm
Been thanked: 1 time

Re: Best solution to attach images to a record

Unread post by deckoff »

Hey, thank you
Since I need to store the x rays in as good quality as possible, 300 kb doesnt cut it. What I am working on is a simple html element added to the xray form

Code: Select all

<form id="data" method="post" enctype="multipart/form-data">
    <!--<input type="text" name="first" value="Bob" />-->
    <!--<input type="text" name="middle" value="James" />-->
    <input type="hidden" name="last" value="" id="xRayName" />
    <input name="image" type="file" />
</form>
jquery, triggered by the save button:

Code: Select all

$( "#nuSaveButton" ).click(function() {
    // e.preventDefault();
    

    var xRayName = $("#pro_name").val();
    $("#xRayName").val(xRayName);
    
    console.log(xRayName);  
    
    
    var formData = new FormData(data);


    console.log(formData)
    $.ajax({
        url:"upload.php",
        type: 'POST',
        data: formData,
        success: function (data) {
            console.log(data)
        },
        cache: false,
        contentType: false,
        processData: false
    });
});
Upon clicking save, nuBuilder will save the file on the server, and create entry in the nuBuilder database, that stores the name of the file, and the customer it belongs to.
I plan add some simple query, that will open the xray in broweser window upon clicking the subform entry of the name
A few things still need to be ironed out.
any suggestions welcome
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Best solution to attach images to a record

Unread post by toms »

Hi,

This form thread might also be useful. It's about uploading files to the server & downloading them.
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Best solution to attach images to a record

Unread post by toms »

deckoff wrote: any suggestions welcome
I wouldn't do it in this way (will not be triggered if the save shortcut is pressed)

Code: Select all

$( "#nuSaveButton" ).click(function() {
...
});
Instead, I'd add a nuBeforeSave() event handler:

Code: Select all

function nuBeforeSave() {

    if (nuFORM.edited === true) {
         Run your Code here....
    }

    return true;
}
deckoff
Posts: 17
Joined: Tue Jul 10, 2018 12:34 pm
Been thanked: 1 time

Re: Best solution to attach images to a record

Unread post by deckoff »

Hmmm, I also have the problem that values added with

Code: Select all

$( "#pro_code" ).val("test")
where pro_code is and input id, value get deleted, and the filed is empty. If I add it manually, it stays.
Could that help?
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Best solution to attach images to a record

Unread post by toms »

Hi,

You need to invoke .change() otherwise the value will not be saved to the DB.

Code: Select all

( "#pro_code" ).val("test").change();
deckoff
Posts: 17
Joined: Tue Jul 10, 2018 12:34 pm
Been thanked: 1 time

Re: Best solution to attach images to a record

Unread post by deckoff »

Thanx, worked like charm!!!
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Best solution to attach images to a record

Unread post by admin »

.
Post Reply