
Offers a client SDK for accessing file-related features like login, file upload/download, and folder management. Missing shared folder support, link features, and user support.
Mega client SDK implemented for Kotlin Multiplatform. Basically a re-implementation of the go-mega library in Kotlin.
This library is currently focused on file access, so not all features available in official SDK's are available.
Features:
Whats missing:
Add the repository:
repositories {
mavenCentral()
}Put in your dependencies block:
implementation("dev.carlsen.mega:mega:1.0.0-beta08")// Initialize the SDK
val mega = Mega()
// Log in to your MEGA account
mega.login("email@example.com", "password")
// Access your files
val fs = mega.getFileSystem()
val rootNode = fs.root
val files = mega.getChildren(rootNode!!)
// Download a file
val file = files.first { it.name == "example.pdf" }
SystemFileSystem.sink(Path("download.pdf")).use { fileOutputSink ->
mega.downloadFile(
src = file,
fileOutputSink = ProgressCountingSink(
delegate = fileOutputSink,
totalBytes = file.size,
onProgress = { b, t ->
println("Downloaded $b of $t bytes")
}
).buffered(),
cancellationToken = CancellationToken.default()
)
}
// Upload a file
val fileToUpload = Path("documents/report.pdf")
SystemFileSystem.source(fileToUpload).use { fileSource ->
mega.uploadFile(
destNode = rootNode,
name = "uploaded-report.pdf",
fileSize = fileSource.size(),
fileInputSource = fileSource.buffered(),
cancellationToken = CancellationToken.default()
)
}
// Create a folder
val newFolder = mega.createFolder(rootNode, "My New Folder")
// Delete a node (with optional permanent deletion)
mega.delete(file, destroy = true)
// Enable logging
mega.logger.addListener(object : LogListener {
override fun onLogMessage(level: LogLevel, message: String, throwable: Throwable?) {
println("[$level] $message")
throwable?.printStackTrace()
}
})
// Cancel operations with cancellation token
val cancellationToken = CancellationToken()
try {
mega.uploadFile(
destNode = rootNode,
name = "large-file.zip",
fileSize = largeFileSource.size(),
fileInputSource = largeFileSource,
cancellationToken = cancellationToken
)
} catch (e: Exception) {
// Handle cancellation
}
// Call cancel() from another thread to stop the operation
cancellationToken.cancel()
// Logout when done
mega.logout()Mega client SDK implemented for Kotlin Multiplatform. Basically a re-implementation of the go-mega library in Kotlin.
This library is currently focused on file access, so not all features available in official SDK's are available.
Features:
Whats missing:
Add the repository:
repositories {
mavenCentral()
}Put in your dependencies block:
implementation("dev.carlsen.mega:mega:1.0.0-beta08")// Initialize the SDK
val mega = Mega()
// Log in to your MEGA account
mega.login("email@example.com", "password")
// Access your files
val fs = mega.getFileSystem()
val rootNode = fs.root
val files = mega.getChildren(rootNode!!)
// Download a file
val file = files.first { it.name == "example.pdf" }
SystemFileSystem.sink(Path("download.pdf")).use { fileOutputSink ->
mega.downloadFile(
src = file,
fileOutputSink = ProgressCountingSink(
delegate = fileOutputSink,
totalBytes = file.size,
onProgress = { b, t ->
println("Downloaded $b of $t bytes")
}
).buffered(),
cancellationToken = CancellationToken.default()
)
}
// Upload a file
val fileToUpload = Path("documents/report.pdf")
SystemFileSystem.source(fileToUpload).use { fileSource ->
mega.uploadFile(
destNode = rootNode,
name = "uploaded-report.pdf",
fileSize = fileSource.size(),
fileInputSource = fileSource.buffered(),
cancellationToken = CancellationToken.default()
)
}
// Create a folder
val newFolder = mega.createFolder(rootNode, "My New Folder")
// Delete a node (with optional permanent deletion)
mega.delete(file, destroy = true)
// Enable logging
mega.logger.addListener(object : LogListener {
override fun onLogMessage(level: LogLevel, message: String, throwable: Throwable?) {
println("[$level] $message")
throwable?.printStackTrace()
}
})
// Cancel operations with cancellation token
val cancellationToken = CancellationToken()
try {
mega.uploadFile(
destNode = rootNode,
name = "large-file.zip",
fileSize = largeFileSource.size(),
fileInputSource = largeFileSource,
cancellationToken = cancellationToken
)
} catch (e: Exception) {
// Handle cancellation
}
// Call cancel() from another thread to stop the operation
cancellationToken.cancel()
// Logout when done
mega.logout()