Creates a new UploadJob instance
Initializes an upload job with the provided metadata and optional URI. The upload job represents a single file being uploaded to a drive.
Upload job metadata
Optionaluri: stringOptional URI path for the upload job endpoint. Defaults to '/drive/:driveId/upload'
Get the upload job ID
Get the presigned URL
Get the presigned URL expiration date
Get the filename
Get the MIME type
Get the file size
Get the file path
Get the upload status
Get the failed URL
Get the status URL
Check if the entity is active
This method checks the active status of the entity. Most entities in the system can be active or inactive, which affects their availability and usability in the platform.
True if the entity is active, false otherwise
Convert model instance to interface data
This method serializes the model instance to a plain object that matches the interface type. This is useful for:
The model data as a plain object matching the interface type
Convert model instance to API payload
This method creates a payload suitable for API requests by:
A clean object suitable for API requests
Update model data with new values
This method updates the model's data and instance properties with new values. It performs a shallow merge of the updates with existing data, allowing for partial updates of the model's properties.
Object containing properties to update
const user = new User({
email: 'old@example.com',
firstName: 'John'
});
// Update multiple properties
user.update({
email: 'new@example.com',
lastName: 'Doe'
});
// Save changes to API
await user.save();
This method only updates the local model instance. To persist changes to the API, call save after updating.
Save the model instance to the API
This method persists the current state of the model to the API using a PUT request. It requires the model to have an ID (existing instance). For new instances, use the collection's create method instead.
The method:
Promise resolving to the updated model data
Delete the model instance from the API
This method permanently deletes the model instance from the API and clears the local data. This operation cannot be undone.
The method:
Promise that resolves when deletion is successful
Mark this upload job as failed
Marks the upload as failed and automatically reverts the reserved drive quota. This should be called when the client-side upload fails. Uses the failed_url provided by the API.
OptionalerrorMessage: stringError message describing the failure
Promise resolving to updated upload job data
Upload item to drive using upload
Uploads an item to the drive using the presigned URL with all required headers, including the server-side encryption header required by the bucket policy.
The File or Blob to upload
Optionaloptions: { onProgress?: (progress: number) => void }Optional upload options
OptionalonProgress?: (progress: number) => voidOptional progress callback that receives upload progress (0-100)
Promise that resolves when upload completes successfully
const fileInput = document.getElementById('fileInput') as HTMLInputElement;
const file = fileInput.files[0];
const result = await drive.items.uploadFiles([file]);
const uploadJob = result.uploadJobs[0];
try {
await uploadJob.upload(file, {
onProgress: (progress) => {
console.log(`Upload progress: ${progress}%`);
}
});
console.log('Upload successful!');
} catch (error) {
console.error('Upload failed:', error);
await uploadJob.markFailed(error.message);
}
UploadJob class for tracking individual file uploads
This class represents an individual file upload job in the Mosaia platform. Each UploadJob tracks one file being uploaded to drive via presigned URL. After successful upload, the storage-manager Lambda creates a DriveItem from the UploadJob.
Features:
Remarks
Upload workflow:
Example
Basic upload job:
Example
Check upload status:
Example
Mark upload as failed: