Learn how to query, view, download and upload files to the server file system or database tables using Sharperlight via the Web Channel
• Query the file system using System / File List table
• How to specify trusted and secured folder location in Site Setup
• Display file system images in the Web Channel
• Display database images in the Web Channel
• How to upload, view and delete files to the Web Channel using a RESTful API POST
• How to upload files into a database with writeback
Notes:
Sharperlight v4.7.153 or higher is required.
The training materials can be downloaded here TrainFF1.
In Publisher Import the file TrainFF1.pbqlist
Upload File Expression
<ExpressStore:MyName>
<button class=’k-button’ onclick=”ViewFile(‘[_OrderNo]’);”>View</button>
<label for=’fup[_OrderNo]’ class=’k-button’>Upload</label>
<input id=’fup[_OrderNo]’ type=”file” style=’display:none;’ onchange=”UploadFile(event,'[_OrderNo]’);”>
<button class=’k-button’ onclick=”DeleteFile(‘[_OrderNo]’);”>Delete</button>
</ExpressStore>
Replace(
ValueStoreGet(“MyName”)
,”[_OrderNo]”,JavaScriptEncode( {%OrdNo} ))
Upload File JavaScript Resource File
<!–ReportContentSectionBegin–>
<script>
var _saveFolder = “..\\Invoice\\”; //under secured folder in Site Setup
function UploadFile( e,docNo ) {
try {
var fr = new FileReader;
fr.onloadend = function() {
PostData(‘update’,_saveFolder + docNo + ‘.jpg’,fr.result);
};
var file = e.target.files[0];
//alert(file.name);
fr.readAsDataURL(file);
}
catch(err) {
alert(err);
}
}
function DeleteFile( docNo ) {
kendo.confirm(‘Delete ‘ + docNo + ‘?’).then( function () {
PostData(‘delete’,_saveFolder + docNo + ‘.jpg’,”);
});
}
function ViewFile( docNo ) {
varurl = ‘{*Url.Root}/File/SecuredHash/’ + Base64Encode(_saveFolder + docNo + ‘.jpg’) + ‘?usid={_System.Rest.Usid}’;
WinOverlayExtShow(url,’File:’+docNo,800,700);
}
function PostData(action,path,data) {
//alert(‘action:’+action + ‘ path:’+path+ ‘ data:’+ data.substring(0, 100));
var fileObj = {
action: action,
path: path,
data: data
}
$.ajax({
type: “POST”,
url: ‘{*Url.Root}/FilePost?usid={_System.Rest.Usid}’,
data: JSON.stringify(fileObj),
success: PostSuccess,
dataType: ‘json’
});
}
function PostSuccess(e) {
//FilePost returns JSON object with status of post
if( e.errorMessage != null && e.errorMessage.length> 0 ) {
alert(e.errorMessage);
}
}
function Base64Encode(str) {
returnbtoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
functiontoSolidBytes(match, p1) {
returnString.fromCharCode(‘0x’ + p1);
}));
}
</script>
<!–ReportContentSectionEnd–>