← All articles
Asset Management
OneDrive for Drupal Asset Management
Implement automatic media uploads to OneDrive with version control, drag-and-drop UI in Drupal's media browser, and granular sharing settings.
Published January 20, 2024
drupalonedrivemedia-managementcloud-storageasset-managementoffice365
Overview
OneDrive integration for Drupal extends your media library capabilities by leveraging Microsoft’s cloud storage. This solution provides automatic uploads, intelligent version control, and a modern drag-and-drop interface while maintaining all files in OneDrive for Business.
Features
- Automatic media uploads to OneDrive
- Version control and file history
- Drag-and-drop media browser interface
- Granular sharing permissions tied to Office 365
- Thumbnail generation and preview
- Bulk upload and batch operations
- Media metadata synchronization
- Integration with Drupal’s media library
Technical Details
Technologies: Microsoft Graph API, OneDrive for Business, Drupal Media Library, Drupal Entity API, JavaScript File API, OAuth 2.0
Requirements:
- Drupal 9.x or 10.x with Media module
- OneDrive for Business subscription
- Azure AD app with Files.ReadWrite permission
- Modern browser with File API support
- Drupal Media Library module enabled
API Endpoints:
Upload session: POST /me/drive/root:/{path}:/createUploadSession
Upload chunk: PUT /me/drive/root:/{path}:/createUploadSession
List files: GET /me/drive/root/children
Get thumbnails: GET /me/drive/items/{item-id}/thumbnails
Implementation
- Configure Azure AD app with OneDrive permissions
- Create custom media source plugin for OneDrive
- Implement chunked upload for large files
- Build drag-and-drop upload widget
- Create media entity type for OneDrive files
- Implement thumbnail generation service
- Add version control tracking
- Configure sharing permission management
- Implement background sync queue
- Add comprehensive upload progress tracking
<?php
// Example: OneDrive media source plugin
namespace Drupal\onedrive_integration\Plugin\media\Source;
use Drupal\media\MediaSourceBase;
/**
* @MediaSource(
* id = "onedrive",
* label = @Translation("OneDrive"),
* description = @Translation("Store media files in OneDrive for Business"),
* allowed_field_types = {"string"},
* default_thumbnail_filename = "onedrive.png"
* )
*/
class OneDrive extends MediaSourceBase {
public function getMetadata(MediaInterface $media, $name) {
$file_id = $this->getSourceFieldValue($media);
switch ($name) {
case 'thumbnail_uri':
return $this->getThumbnailUri($file_id);
case 'name':
return $this->getFileName($file_id);
case 'filesize':
return $this->getFileSize($file_id);
default:
return parent::getMetadata($media, $name);
}
}
protected function getThumbnailUri($file_id) {
$graph_client = \Drupal::service('onedrive_integration.graph_client');
return $graph_client->getThumbnailUrl($file_id, 'large');
}
}
Use Cases
- Marketing teams managing large media libraries
- Organizations with strict version control requirements
- Remote teams collaborating on visual content
- Publishing workflows requiring approval chains
- Digital asset management for distributed teams
Benefits
- Unlimited cloud storage capacity with OneDrive
- Automatic version history and rollback
- Reduced Drupal server storage costs
- Enhanced collaboration with Office 365 users
- Built-in malware scanning and security
- Seamless mobile access to media files
- Integrated backup and disaster recovery