Skip to content
Products
Docs
Pricing
Blog
Log In
Sign Up
Docs
Docs
CODE
On this page

Storage System

How UNA 15 modules store, serve, protect, and delete files through storage objects and engines.
Android
iOS
Web
Core
~15.0
Copy Page
Note
Tip
CREATE TABLE IF NOT EXISTS `bx_posts_covers` (
	`id` int(11) NOT NULL AUTO_INCREMENT,
	`profile_id` int(10) unsigned NOT NULL,
	`remote_id` varchar(128) NOT NULL,
	`path` varchar(255) NOT NULL,
	`file_name` varchar(255) NOT NULL,
	`mime_type` varchar(128) NOT NULL,
	`ext` varchar(32) NOT NULL,
	`size` bigint(20) NOT NULL,
	`added` int(11) NOT NULL,
	`modified` int(11) NOT NULL,
	`private` int(11) NOT NULL,
	`dimensions` varchar(12) NOT NULL,
	PRIMARY KEY (`id`),
	UNIQUE KEY `remote_id` (`remote_id`)
);
SET @sStorageEngine = (SELECT `value` FROM `sys_options` WHERE `name` = 'sys_storage_default');

INSERT INTO `sys_objects_storage` (`object`, `engine`, `params`, `token_life`, `cache_control`, `levels`, `table_files`, `ext_mode`, `ext_allow`, `ext_deny`, `quota_size`, `current_size`, `quota_number`, `current_number`, `max_file_size`, `ts`) VALUES
('bx_posts_photos', @sStorageEngine, '', 360, 2592000, 3, 'bx_posts_photos', 'allow-deny', '{image}', '', 0, 0, 0, 0, 0, 0),
('bx_posts_files', @sStorageEngine, '', 360, 2592000, 3, 'bx_posts_files', 'deny-allow', '', '{dangerous}', 0, 0, 0, 0, 0, 0);
'OBJECT_STORAGE' => 'bx_posts_covers',
'OBJECT_STORAGE_FILES' => 'bx_posts_files',
'OBJECT_STORAGE_PHOTOS' => 'bx_posts_photos',
'OBJECT_STORAGE_VIDEOS' => 'bx_posts_videos',
'OBJECT_STORAGE_SOUNDS' => 'bx_posts_sounds',
$CNF = &$this->_oConfig->CNF;

$oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_FILES']);
if (!$oStorage)
	return false;

// the second argument is $isPrivate, and it defaults to true
$iFileId = $oStorage->storeFileFromForm($_FILES['file'], false, $iProfileId);
if (!$iFileId)
	return $oStorage->getErrorString(); // or getErrorCode()

// the id is now saved on your content row, so the upload is no longer a ghost
$oStorage->afterUploadCleanup($iFileId, $iProfileId);

$sUrl = $oStorage->getFileUrlById($iFileId);
$aFile = $oStorage->getFile($iFileId); // files-table row, or false
Tip
Important
Note
Tip
Tip
DELETE FROM `sys_objects_storage` WHERE `object` LIKE 'bx_posts_%';
DELETE FROM `sys_storage_tokens` WHERE `object` LIKE 'bx_posts_%';
8d
On this page
EnginesObject settingsFiles tableRegister an objectStore and read filesQuotasServe filesGhostsDeleting filesUninstalling a moduleTranscodersAlertsRelated pages
Auto
Introduction
Getting Started
Configuration
Apps
CODE
Developer Architecture
Code Convention
Code Quality
Directory Structure
How to Add an App
Storage System
Common Mistakes
Payment Provider Integration
Module API
iOS Client
NEO Developer
Android Client
Web Client
Contributing
REST API
Analytics Developer
Auth
Connect
CREATE TABLE IF NOT EXISTS `bx_posts_covers` (
	`id` int(11) NOT NULL AUTO_INCREMENT,
	`profile_id` int(10) unsigned NOT NULL,
	`remote_id` varchar(128) NOT NULL,
	`path` varchar(255) NOT NULL,
	`file_name` varchar(255) NOT NULL,
	`mime_type` varchar(128) NOT NULL,
	`ext` varchar(32) NOT NULL,
	`size` bigint(20) NOT NULL,
	`added` int(11) NOT NULL,
	`modified` int(11) NOT NULL,
	`private` int(11) NOT NULL,
	`dimensions` varchar(12) NOT NULL,
	PRIMARY KEY (`id`),
	UNIQUE KEY `remote_id` (`remote_id`)
);
SET @sStorageEngine = (SELECT `value` FROM `sys_options` WHERE `name` = 'sys_storage_default');

INSERT INTO `sys_objects_storage` (`object`, `engine`, `params`, `token_life`, `cache_control`, `levels`, `table_files`, `ext_mode`, `ext_allow`, `ext_deny`, `quota_size`, `current_size`, `quota_number`, `current_number`, `max_file_size`, `ts`) VALUES
('bx_posts_photos', @sStorageEngine, '', 360, 2592000, 3, 'bx_posts_photos', 'allow-deny', '{image}', '', 0, 0, 0, 0, 0, 0),
('bx_posts_files', @sStorageEngine, '', 360, 2592000, 3, 'bx_posts_files', 'deny-allow', '', '{dangerous}', 0, 0, 0, 0, 0, 0);
'OBJECT_STORAGE' => 'bx_posts_covers',
'OBJECT_STORAGE_FILES' => 'bx_posts_files',
'OBJECT_STORAGE_PHOTOS' => 'bx_posts_photos',
'OBJECT_STORAGE_VIDEOS' => 'bx_posts_videos',
'OBJECT_STORAGE_SOUNDS' => 'bx_posts_sounds',
$CNF = &$this->_oConfig->CNF;

$oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE_FILES']);
if (!$oStorage)
	return false;

// the second argument is $isPrivate, and it defaults to true
$iFileId = $oStorage->storeFileFromForm($_FILES['file'], false, $iProfileId);
if (!$iFileId)
	return $oStorage->getErrorString(); // or getErrorCode()

// the id is now saved on your content row, so the upload is no longer a ghost
$oStorage->afterUploadCleanup($iFileId, $iProfileId);

$sUrl = $oStorage->getFileUrlById($iFileId);
$aFile = $oStorage->getFile($iFileId); // files-table row, or false