Page 1 of 1

File Object Not Saving File

Posted: Wed Mar 07, 2018 11:44 am
by tonyd
I have a File Object (in a collection of other objects) in a subform. When I click the "browse" button on the File Object everything seems to work fine . . . file select window pops up, user selects file, filename shows up in the File Object on the subform. However, when I click save on the main form, the filename disappears from the File Object and is replaced with "No file selected." Something is getting saved in the underlying table, but it seems to only save the other objects on the subform, not the File Object.

I hope that is descriptive enough to give everyone a mental image of my problem.

Re: File Object Not Saving File

Posted: Thu Mar 08, 2018 12:37 am
by admin
tonyd,

Can you give us a screenshot?

Steven

Re: File Object Not Saving File

Posted: Thu Mar 08, 2018 6:54 pm
by tonyd
Before adding a file
beforeselection.jpg
After selecting a file
beforesave.jpg
After clicking "save"
aftersave.jpg

Re: File Object Not Saving File

Posted: Thu Mar 08, 2018 8:26 pm
by admin
tonyd,

That is the way it is supposed to work.

An Input:File Object is for selecting a file, not for displaying anything.

Just like in the Files Form.
input_file_object.PNG
Steven

Re: File Object Not Saving File

Posted: Fri Mar 09, 2018 1:03 am
by tonyd
I think I understand. Then what I need to know is whether I can store the file somewhere (database, filesystem, cloud) that would allow for later retrieval? The filesystem would be the best due to the expected large numbers of saved files, but that would go against the whole nuBuilder idea of keeping everything in one easy-to-manage location, the database. I know a MySQL database can hold quite large file sizes, but I just don't trust a database for file storage.

BTW, I am not really concerned (yet) with displaying the files.

Re: File Object Not Saving File

Posted: Fri Mar 09, 2018 1:43 am
by admin
tonyd,

Even though an Input:File Object doesn't display the file name after it saves, it will still save the file to the database once you click the Save Button.


Steven

Re: File Object Not Saving File

Posted: Fri Mar 09, 2018 11:45 am
by tonyd
OK, is there a way within nuBuilder to download or view the file (assuming it is a PDF or graphics file) once it is in the database?

Re: File Object Not Saving File

Posted: Fri Mar 09, 2018 11:05 pm
by admin
TonyD,

The File Button will lead you to a Form that has code that is used to display files.
displaying_files.PNG
This is that code...

Code: Select all


nuSetNoSearchColumns([2,3]);

$('[data-nu-column="0"]').each(function( index ) {

    var code    = '#nucell_' + index + '_';
    window.nuImages[$(code + '0').text()] = $(code + '2').text();
    
});



if(nuFormType() == 'browse'){
    nuShowBrowseImages()
}else{
    nuShowFile();
}




function nuBeforeSave(){

    var f   = $('#sfi_json_file').val();
    
    if(f != ''){
        
        $('#sfi_json')
        .val(f)
        .change();
        
    }
    
    return true;

}


function nuShowFile(){
    
    var j   = $('#sfi_json').val();
    	
	if(j == ''){return;}
	
	var ob	= JSON.parse(j)
	var ty	= ob.type;
	var ur	= atob(ob.file);
    var x   = document.createElement("EMBED");
    
    x.setAttribute("type", ty);
    x.setAttribute("src", ur);
    x.setAttribute("width", "300px");
    x.setAttribute("height", "300px");

    $('#view_image').html('');
    document.getElementById('view_image').appendChild(x);
        
}


function nuShowBrowseImages(){

    $('[data-nu-column="0"]').each(function( index ) {
		
		var p	    = $(this).attr('id');
		var r	    = String(p).split('_')[1];
		var i       = "nucell_" + r + "_2";
		var e       = "nucell_" + r + "_3";
		var h       = $('#' + i).html();

		if(h != '' && h !== undefined){

        	var ob	= JSON.parse(h)
        	var ty	= ob.type;
        	var ur	= atob(ob.file);
            var x   = document.createElement("EMBED");
            
            x.setAttribute("type", "embed" + i);
            x.setAttribute("type", ty);
            x.setAttribute("src", ur);
            x.setAttribute("width", "140px");
            x.setAttribute("height", "140px");

            $('#' + e).html('');
            document.getElementById(e).appendChild(x);
        
		}
		
	});

}



Steven

Re: File Object Not Saving File

Posted: Sat Mar 10, 2018 12:46 pm
by tonyd
Thanks Steven. I will give this a try.

Re: File Object Not Saving File

Posted: Mon Mar 12, 2018 3:26 am
by admin
.