eLabSDK.Experiment.Section.File
Functions
| Name | Description |
|---|---|
| getFiles() | Get all files associated with this file section. |
This retrieves an array of eLabSDK.ExperimentFile objects representing all files that have
been uploaded to this section. Each file object includes the file ID, name, download URL,
and storage timestamp. Returns an empty array if no files are present. Use this to access
file information, create download links, or display file listings for the section.
addImportButtons(callback, actionName, btnContent) | Add custom import buttons to all file sections in the experiment.
This creates custom "Add [X] File" buttons next to the standard "Add File" button in every
file section of the experiment. The buttons are automatically styled to match existing buttons
and positioned appropriately. When clicked, the button executes your custom callback to handle
file import from external sources (cloud storage, integrations, etc.). Use this to enable
importing files from custom sources like external storage systems, APIs, or third-party services.
uploadFiles(imageOnly, fromSection, files, [dropElement]) | Upload files to this file section.
This handles uploading one or more files to the specified experiment section. Supports both
standard remote storage and local storage modes. Files can be regular files or images, with
different handling for each type. The upload includes progress tracking, chunked uploads for
large files, file validation (extension blacklist for security), and confirmation dialogs
for bulk uploads (5+ files). Use this to programmatically upload files from external sources,
drag-and-drop handlers, or custom file selection interfaces.
_handleLocalStorageFileUploaded(section, filename, obj) | Finalize the upload on local server
_onLocalStorageUploadError(filename, message) | Display the errors that happens when we upload on the local server
getFiles()
Get all files associated with this file section.
This retrieves an array of eLabSDK.ExperimentFile objects representing all files that have
been uploaded to this section. Each file object includes the file ID, name, download URL,
and storage timestamp. Returns an empty array if no files are present. Use this to access
file information, create download links, or display file listings for the section.
Kind: global function
Returns: Array.<eLabSDK.ExperimentFile> - Array of ExperimentFile objects for files in this section
Example
// Get and display all files in a section
var experiment = new eLabSDK.Experiment({
experimentID: 123,
onLoaded: function() {
var section = this.sections[0];
if (section instanceof eLabSDK.Experiment.Section.File) {
var files = section.getFiles();
console.log('Section contains ' + files.length + ' files');
files.forEach(function(file) {
console.log('- ' + file.name + ' (stored: ' + file.stored + ')');
});
}
}
});
Example
// Create download links for all files
var experiment = new eLabSDK.Experiment({
experimentID: 456,
onLoaded: function() {
var fileSection = this.getSection(789);
var files = fileSection.getFiles();
var $container = $('#fileDownloads');
files.forEach(function(file) {
var $link = $('<a href="' + file.download + '" target="_blank">' +
file.name + '</a><br>');
$container.append($link);
});
}
});
Example
// Check if section has files
var experiment = new eLabSDK.Experiment({
experimentID: 321,
onLoaded: function() {
var section = this.getSection(555);
var files = section.getFiles();
if (files && files.length > 0) {
console.log('Section has ' + files.length + ' file(s)');
enableFileOperations();
} else {
console.log('Section has no files');
}
}
});
addImportButtons(callback, actionName, btnContent)
Add custom import buttons to all file sections in the experiment.
This creates custom "Add [X] File" buttons next to the standard "Add File" button in every
file section of the experiment. The buttons are automatically styled to match existing buttons
and positioned appropriately. When clicked, the button executes your custom callback to handle
file import from external sources (cloud storage, integrations, etc.). Use this to enable
importing files from custom sources like external storage systems, APIs, or third-party services.
Kind: global function
| Param | Type | Description |
|---|---|---|
| callback | function | Function called when import button is clicked. Receives (isImage, sectionID) as parameters. |
| callback.isImage | boolean | True if the section is for images, false for regular files |
| callback.sectionID | string | The section ID where the file should be added |
| actionName | string | Unique name for this import action (used in button IDs) |
| btnContent | string | HTML content to display in the button (text and/or icon) |
Example
// Add Dropbox import button to all file sections
eLabSDK.ready(function() {
var experimentPage = new eLabSDK.Page.Experiment({
onReady: function() {
var exp = this.getExperimentObject();
exp.sections.forEach(function(section) {
if (section instanceof eLabSDK.Experiment.Section.File) {
section.addImportButtons(
function(isImage, sectionID) {
openDropboxFilePicker(sectionID, isImage);
},
'Dropbox',
'<i class="fab fa-dropbox"></i> Add from Dropbox'
);
}
});
}
});
});
Example
// Add Google Drive import
var fileSection = new eLabSDK.Experiment.Section.File({
experiment: experimentObj,
sectionID: 123
});
fileSection.addImportButtons(
function(isImage, sectionID) {
console.log('Importing to section: ' + sectionID);
console.log('Is image section: ' + isImage);
// Open Google Drive picker
openGoogleDrivePicker({
onSelect: function(files) {
uploadFilesFromGoogleDrive(files, sectionID, isImage);
}
});
},
'GoogleDrive',
'<i class="fab fa-google-drive"></i> Add from Drive'
);
Example
// Add network share import
var fileSection = new eLabSDK.Experiment.Section.File({
experiment: experimentObj,
sectionID: 456
});
fileSection.addImportButtons(
function(isImage, sectionID) {
var networkPath = prompt('Enter network file path:');
if (networkPath) {
importFromNetworkShare(networkPath, sectionID, isImage);
}
},
'NetworkShare',
'<i class="fas fa-network-wired"></i> Add from Network'
);
uploadFiles(imageOnly, fromSection, files, [dropElement])
Upload files to this file section.
This handles uploading one or more files to the specified experiment section. Supports both
standard remote storage and local storage modes. Files can be regular files or images, with
different handling for each type. The upload includes progress tracking, chunked uploads for
large files, file validation (extension blacklist for security), and confirmation dialogs
for bulk uploads (5+ files). Use this to programmatically upload files from external sources,
drag-and-drop handlers, or custom file selection interfaces.
Kind: global function
| Param | Type | Description |
|---|---|---|
| imageOnly | boolean | True if uploading images, false for regular files (affects storage location) |
| fromSection | string | number | The section ID where files should be uploaded |
| files | Array.<Object> | Array of file objects to upload. Can be File objects or objects with {name, link, headers} |
| [dropElement] | string | Optional CSS selector for drag-and-drop target element |
Example
// Upload files from file input
var fileSection = new eLabSDK.Experiment.Section.File({
experiment: experimentObj,
sectionID: 123
});
$('#fileInput').on('change', function(e) {
var files = Array.from(e.target.files);
fileSection.uploadFiles(
false, // Not images
123, // Section ID
files, // File array
'#dropZone' // Drop element
);
});
Example
// Upload images from external source
var fileSection = new eLabSDK.Experiment.Section.File({
experiment: experimentObj,
sectionID: 456
});
// Files from external API with download links
var externalImages = [
{ name: 'result1.png', link: 'https://external.com/files/1' },
{ name: 'result2.png', link: 'https://external.com/files/2' }
];
fileSection.uploadFiles(
true, // Images only
456, // Section ID
externalImages // External file objects
);
Example
// Upload with authentication headers
var fileSection = new eLabSDK.Experiment.Section.File({
experiment: experimentObj,
sectionID: 789
});
var filesToUpload = [
{
name: 'data.csv',
link: 'https://api.external.com/file/123',
headers: [
{ key: 'Authorization', value: 'Bearer TOKEN123' },
{ key: 'X-Custom-Header', value: 'custom-value' }
]
}
];
fileSection.uploadFiles(false, 789, filesToUpload);
Example
// Bulk upload with confirmation
var fileSection = new eLabSDK.Experiment.Section.File({
experiment: experimentObj,
sectionID: 101
});
// Will show confirmation for 10 files
var manyFiles = Array.from(fileInputElement.files);
fileSection.uploadFiles(false, 101, manyFiles);
_handleLocalStorageFileUploaded(section, filename, obj)
Finalize the upload on local server
Kind: global function
| Param | Type | Description |
|---|---|---|
| section | Experiment.Section | : section we want to add the file(s) to. |
| filename | string | : List of files to upload |
| obj | struct | : File upload info |
_onLocalStorageUploadError(filename, message)
Display the errors that happens when we upload on the local server
Kind: global function
| Param | Type | Description |
|---|---|---|
| filename | string | : file name |
| message | string | : error message |
© 2023 eLabNext
Updated about 11 hours ago