Show / Hide Table of Contents

Class MegaApiClient

Inheritance
System.Object
MegaApiClient
Implements
IMegaApiClient
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: CG.Web.MegaApiClient
Assembly: MegaApiClient.dll
Syntax
public class MegaApiClient : IMegaApiClient

Constructors

| Improve this Doc View Source

MegaApiClient()

Instantiate a new MegaApiClient object with default Options and default IWebClient

Declaration
public MegaApiClient()
| Improve this Doc View Source

MegaApiClient(IWebClient)

Instantiate a new MegaApiClient object with default Options and custom IWebClient

Declaration
public MegaApiClient(IWebClient webClient)
Parameters
Type Name Description
IWebClient webClient
| Improve this Doc View Source

MegaApiClient(Options)

Instantiate a new MegaApiClient object with custom Options and default IWebClient

Declaration
public MegaApiClient(Options options)
Parameters
Type Name Description
Options options
| Improve this Doc View Source

MegaApiClient(Options, IWebClient)

Instantiate a new MegaApiClient object with custom Options and custom IWebClient

Declaration
public MegaApiClient(Options options, IWebClient webClient)
Parameters
Type Name Description
Options options
IWebClient webClient

Properties

| Improve this Doc View Source

IsLoggedIn

Declaration
public bool IsLoggedIn { get; }
Property Value
Type Description
System.Boolean

Methods

| Improve this Doc View Source

CreateFolder(String, INode)

Create a folder on the filesytem

Declaration
public INode CreateFolder(string name, INode parent)
Parameters
Type Name Description
System.String name

Folder name

INode parent

Parent node to attach created folder

Returns
Type Description
INode
Exceptions
Type Condition
System.NotSupportedException

Not logged in

ApiException

Mega.co.nz service reports an error

System.ArgumentNullException

name or parent is null

System.ArgumentException

parent is not valid (all types are allowed expect File)

| Improve this Doc View Source

CreateFolderAsync(String, INode)

Declaration
public Task<INode> CreateFolderAsync(string name, INode parent)
Parameters
Type Name Description
System.String name
INode parent
Returns
Type Description
System.Threading.Tasks.Task<INode>
| Improve this Doc View Source

Delete(INode, Boolean)

Delete a node from the filesytem

Declaration
public void Delete(INode node, bool moveToTrash = true)
Parameters
Type Name Description
INode node

Node to delete

System.Boolean moveToTrash

Moved to trash if true, Permanently deleted if false

Remarks

You can only delete Directory or File node

Exceptions
Type Condition
System.NotSupportedException

Not logged in

ApiException

Mega.co.nz service reports an error

System.ArgumentNullException

node is null

System.ArgumentException

node is not a directory or a file

| Improve this Doc View Source

DeleteAsync(INode, Boolean)

Declaration
public Task DeleteAsync(INode node, bool moveToTrash = true)
Parameters
Type Name Description
INode node
System.Boolean moveToTrash
Returns
Type Description
System.Threading.Tasks.Task
| Improve this Doc View Source

Download(INode, Nullable<CancellationToken>)

Retrieve a Stream to download and decrypt the specified node

Declaration
public Stream Download(INode node, CancellationToken? cancellationToken = null)
Parameters
Type Name Description
INode node

Node to download (only File can be downloaded)

System.Nullable<System.Threading.CancellationToken> cancellationToken

CancellationToken used to cancel the action

Returns
Type Description
System.IO.Stream
Exceptions
Type Condition
System.NotSupportedException

Not logged in

ApiException

Mega.co.nz service reports an error

System.ArgumentNullException

node or outputFile is null

System.ArgumentException

node is not valid (only File can be downloaded)

DownloadException

Checksum is invalid. Downloaded data are corrupted

| Improve this Doc View Source

Download(Uri, Nullable<CancellationToken>)

Retrieve a Stream to download and decrypt the specified Uri

Declaration
public Stream Download(Uri uri, CancellationToken? cancellationToken = null)
Parameters
Type Name Description
System.Uri uri

Uri to download

System.Nullable<System.Threading.CancellationToken> cancellationToken

CancellationToken used to cancel the action

Returns
Type Description
System.IO.Stream
Exceptions
Type Condition
System.NotSupportedException

Not logged in

ApiException

Mega.co.nz service reports an error

System.ArgumentNullException

uri is null

System.ArgumentException

Uri is not valid (id and key are required)

DownloadException

Checksum is invalid. Downloaded data are corrupted

| Improve this Doc View Source

DownloadAsync(INode, IProgress<Double>, Nullable<CancellationToken>)

Declaration
public Task<Stream> DownloadAsync(INode node, IProgress<double> progress = null, CancellationToken? cancellationToken = null)
Parameters
Type Name Description
INode node
System.IProgress<System.Double> progress
System.Nullable<System.Threading.CancellationToken> cancellationToken
Returns
Type Description
System.Threading.Tasks.Task<System.IO.Stream>
| Improve this Doc View Source

DownloadAsync(Uri, IProgress<Double>, Nullable<CancellationToken>)

Declaration
public Task<Stream> DownloadAsync(Uri uri, IProgress<double> progress = null, CancellationToken? cancellationToken = null)
Parameters
Type Name Description
System.Uri uri
System.IProgress<System.Double> progress
System.Nullable<System.Threading.CancellationToken> cancellationToken
Returns
Type Description
System.Threading.Tasks.Task<System.IO.Stream>
| Improve this Doc View Source

DownloadFile(INode, String, Nullable<CancellationToken>)

Download a specified node and save it to the specified file

Declaration
public void DownloadFile(INode node, string outputFile, CancellationToken? cancellationToken = null)
Parameters
Type Name Description
INode node

Node to download (only File can be downloaded)

System.String outputFile

File to save the node to

System.Nullable<System.Threading.CancellationToken> cancellationToken

CancellationToken used to cancel the action

Exceptions
Type Condition
System.NotSupportedException

Not logged in

ApiException

Mega.co.nz service reports an error

System.ArgumentNullException

node or outputFile is null

System.ArgumentException

node is not valid (only File can be downloaded)

DownloadException

Checksum is invalid. Downloaded data are corrupted

| Improve this Doc View Source

DownloadFile(Uri, String, Nullable<CancellationToken>)

Download a specified Uri from Mega and save it to the specified file

Declaration
public void DownloadFile(Uri uri, string outputFile, CancellationToken? cancellationToken = null)
Parameters
Type Name Description
System.Uri uri

Uri to download

System.String outputFile

File to save the Uri to

System.Nullable<System.Threading.CancellationToken> cancellationToken

CancellationToken used to cancel the action

Exceptions
Type Condition
System.NotSupportedException

Not logged in

ApiException

Mega.co.nz service reports an error

System.ArgumentNullException

uri or outputFile is null

System.ArgumentException

Uri is not valid (id and key are required)

DownloadException

Checksum is invalid. Downloaded data are corrupted

| Improve this Doc View Source

DownloadFileAsync(INode, String, IProgress<Double>, Nullable<CancellationToken>)

Declaration
public Task DownloadFileAsync(INode node, string outputFile, IProgress<double> progress = null, CancellationToken? cancellationToken = null)
Parameters
Type Name Description
INode node
System.String outputFile
System.IProgress<System.Double> progress
System.Nullable<System.Threading.CancellationToken> cancellationToken
Returns
Type Description
System.Threading.Tasks.Task
| Improve this Doc View Source

DownloadFileAsync(Uri, String, IProgress<Double>, Nullable<CancellationToken>)

Declaration
public Task DownloadFileAsync(Uri uri, string outputFile, IProgress<double> progress = null, CancellationToken? cancellationToken = null)
Parameters
Type Name Description
System.Uri uri
System.String outputFile
System.IProgress<System.Double> progress
System.Nullable<System.Threading.CancellationToken> cancellationToken
Returns
Type Description
System.Threading.Tasks.Task
| Improve this Doc View Source

DownloadFileAttribute(INode, FileAttributeType, Nullable<CancellationToken>)

Download thumbnail from file attributes (or return null if thumbnail is not available)

Declaration
public Stream DownloadFileAttribute(INode node, FileAttributeType fileAttributeType, CancellationToken? cancellationToken = null)
Parameters
Type Name Description
INode node

Node to download the thumbnail from (only File can be downloaded)

FileAttributeType fileAttributeType

File attribute type to retrieve

System.Nullable<System.Threading.CancellationToken> cancellationToken

CancellationToken used to cancel the action

Returns
Type Description
System.IO.Stream
Exceptions
Type Condition
System.NotSupportedException

Not logged in

ApiException

Mega.co.nz service reports an error

System.ArgumentNullException

node or outputFile is null

System.ArgumentException

node is not valid (only File can be downloaded)

System.InvalidOperationException

file attribute data is invalid

| Improve this Doc View Source

DownloadFileAttributeAsync(INode, FileAttributeType, Nullable<CancellationToken>)

Declaration
public Task<Stream> DownloadFileAttributeAsync(INode node, FileAttributeType fileAttributeType, CancellationToken? cancellationToken = null)
Parameters
Type Name Description
INode node
FileAttributeType fileAttributeType
System.Nullable<System.Threading.CancellationToken> cancellationToken
Returns
Type Description
System.Threading.Tasks.Task<System.IO.Stream>
| Improve this Doc View Source

GenerateAuthInfos(String, String, String)

Generate authentication informations and store them in a serializable object to allow persistence

Declaration
public MegaApiClient.AuthInfos GenerateAuthInfos(string email, string password, string mfaKey = null)
Parameters
Type Name Description
System.String email

email

System.String password

password

System.String mfaKey
Returns
Type Description
MegaApiClient.AuthInfos

MegaApiClient.AuthInfos object containing encrypted data

Exceptions
Type Condition
System.ArgumentNullException

email or password is null

| Improve this Doc View Source

GenerateAuthInfosAsync(String, String)

Declaration
public Task<MegaApiClient.AuthInfos> GenerateAuthInfosAsync(string email, string password)
Parameters
Type Name Description
System.String email
System.String password
Returns
Type Description
System.Threading.Tasks.Task<MegaApiClient.AuthInfos>
| Improve this Doc View Source

GenerateAuthInfosAsync(String, String, String)

Declaration
public Task<MegaApiClient.AuthInfos> GenerateAuthInfosAsync(string email, string password, string mfaKey)
Parameters
Type Name Description
System.String email
System.String password
System.String mfaKey
Returns
Type Description
System.Threading.Tasks.Task<MegaApiClient.AuthInfos>
| Improve this Doc View Source

GetAccountInformation()

Retrieve account (quota) information

Declaration
public IAccountInformation GetAccountInformation()
Returns
Type Description
IAccountInformation

An object containing account information

Exceptions
Type Condition
System.NotSupportedException

Not logged in

ApiException

Mega.co.nz service reports an error

| Improve this Doc View Source

GetAccountInformationAsync()

Declaration
public Task<IAccountInformation> GetAccountInformationAsync()
Returns
Type Description
System.Threading.Tasks.Task<IAccountInformation>
| Improve this Doc View Source

GetDownloadLink(INode)

Retrieve an url to download specified node

Declaration
public Uri GetDownloadLink(INode node)
Parameters
Type Name Description
INode node

Node to retrieve the download link (only File or Directory can be downloaded)

Returns
Type Description
System.Uri

Download link to retrieve the node with associated key

Exceptions
Type Condition
System.NotSupportedException

Not logged in

ApiException

Mega.co.nz service reports an error

System.ArgumentNullException

node is null

System.ArgumentException

node is not valid (only File or Directory can be downloaded)

| Improve this Doc View Source

GetDownloadLinkAsync(INode)

Declaration
public Task<Uri> GetDownloadLinkAsync(INode node)
Parameters
Type Name Description
INode node
Returns
Type Description
System.Threading.Tasks.Task<System.Uri>
| Improve this Doc View Source

GetNodeFromLink(Uri)

Retrieve public properties of a file from a specified Uri

Declaration
public INode GetNodeFromLink(Uri uri)
Parameters
Type Name Description
System.Uri uri

Uri to retrive properties

Returns
Type Description
INode
Exceptions
Type Condition
System.NotSupportedException

Not logged in

ApiException

Mega.co.nz service reports an error

System.ArgumentNullException

uri is null

System.ArgumentException

Uri is not valid (id and key are required)

| Improve this Doc View Source

GetNodeFromLinkAsync(Uri)

Declaration
public Task<INode> GetNodeFromLinkAsync(Uri uri)
Parameters
Type Name Description
System.Uri uri
Returns
Type Description
System.Threading.Tasks.Task<INode>
| Improve this Doc View Source

GetNodes()

Retrieve all filesystem nodes

Declaration
public IEnumerable<INode> GetNodes()
Returns
Type Description
System.Collections.Generic.IEnumerable<INode>

Flat representation of all the filesystem nodes

Exceptions
Type Condition
System.NotSupportedException

Not logged in

ApiException

Mega.co.nz service reports an error

| Improve this Doc View Source

GetNodes(INode)

Retrieve children nodes of a parent node

Declaration
public IEnumerable<INode> GetNodes(INode parent)
Parameters
Type Name Description
INode parent
Returns
Type Description
System.Collections.Generic.IEnumerable<INode>

Flat representation of children nodes

Exceptions
Type Condition
System.NotSupportedException

Not logged in

ApiException

Mega.co.nz service reports an error

System.ArgumentNullException

Parent node is null

| Improve this Doc View Source

GetNodesAsync()

Declaration
public Task<IEnumerable<INode>> GetNodesAsync()
Returns
Type Description
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<INode>>
| Improve this Doc View Source

GetNodesAsync(INode)

Declaration
public Task<IEnumerable<INode>> GetNodesAsync(INode parent)
Parameters
Type Name Description
INode parent
Returns
Type Description
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<INode>>
| Improve this Doc View Source

GetNodesFromLink(Uri)

Retrieve list of nodes from a specified Uri

Declaration
public IEnumerable<INode> GetNodesFromLink(Uri uri)
Parameters
Type Name Description
System.Uri uri

Uri

Returns
Type Description
System.Collections.Generic.IEnumerable<INode>
Exceptions
Type Condition
System.NotSupportedException

Not logged in

ApiException

Mega.co.nz service reports an error

System.ArgumentNullException

uri is null

System.ArgumentException

Uri is not valid (id and key are required)

| Improve this Doc View Source

GetNodesFromLinkAsync(Uri)

Declaration
public Task<IEnumerable<INode>> GetNodesFromLinkAsync(Uri uri)
Parameters
Type Name Description
System.Uri uri
Returns
Type Description
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<INode>>
| Improve this Doc View Source

GetRecoveryKey()

Retrieve recovery key

Declaration
public string GetRecoveryKey()
Returns
Type Description
System.String
Exceptions
Type Condition
System.NotSupportedException

Not logged in

| Improve this Doc View Source

GetRecoveryKeyAsync()

Declaration
public Task<string> GetRecoveryKeyAsync()
Returns
Type Description
System.Threading.Tasks.Task<System.String>
| Improve this Doc View Source

GetSessionsHistory()

Retrieve session history

Declaration
public IEnumerable<ISession> GetSessionsHistory()
Returns
Type Description
System.Collections.Generic.IEnumerable<ISession>

A collection of sessions

Exceptions
Type Condition
System.NotSupportedException

Not logged in

ApiException

Mega.co.nz service reports an error

| Improve this Doc View Source

GetSessionsHistoryAsync()

Declaration
public Task<IEnumerable<ISession>> GetSessionsHistoryAsync()
Returns
Type Description
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<ISession>>
| Improve this Doc View Source

Login()

Login anonymously to Mega.co.nz service

Declaration
public void Login()
Exceptions
Type Condition
ApiException

Throws if service is not available

| Improve this Doc View Source

Login(MegaApiClient.AuthInfos)

Login to Mega.co.nz service using hashed credentials

Declaration
public MegaApiClient.LogonSessionToken Login(MegaApiClient.AuthInfos authInfos)
Parameters
Type Name Description
MegaApiClient.AuthInfos authInfos

Authentication informations generated by GenerateAuthInfos(String, String, String) method

Returns
Type Description
MegaApiClient.LogonSessionToken
Exceptions
Type Condition
ApiException

Service is not available or authInfos is invalid

System.ArgumentNullException

authInfos is null

System.NotSupportedException

Already logged in

| Improve this Doc View Source

Login(MegaApiClient.LogonSessionToken)

Declaration
public void Login(MegaApiClient.LogonSessionToken logonSessionToken)
Parameters
Type Name Description
MegaApiClient.LogonSessionToken logonSessionToken
| Improve this Doc View Source

Login(String, String)

Login to Mega.co.nz service using email/password credentials

Declaration
public MegaApiClient.LogonSessionToken Login(string email, string password)
Parameters
Type Name Description
System.String email

email

System.String password

password

Returns
Type Description
MegaApiClient.LogonSessionToken
Exceptions
Type Condition
ApiException

Service is not available or credentials are invalid

System.ArgumentNullException

email or password is null

System.NotSupportedException

Already logged in

| Improve this Doc View Source

Login(String, String, String)

Login to Mega.co.nz service using email/password credentials

Declaration
public MegaApiClient.LogonSessionToken Login(string email, string password, string mfaKey)
Parameters
Type Name Description
System.String email

email

System.String password

password

System.String mfaKey
Returns
Type Description
MegaApiClient.LogonSessionToken
Exceptions
Type Condition
ApiException

Service is not available or credentials are invalid

System.ArgumentNullException

email or password is null

System.NotSupportedException

Already logged in

| Improve this Doc View Source

LoginAnonymous()

Login anonymously to Mega.co.nz service

Declaration
public void LoginAnonymous()
Exceptions
Type Condition
ApiException

Throws if service is not available

| Improve this Doc View Source

LoginAnonymousAsync()

Declaration
public Task LoginAnonymousAsync()
Returns
Type Description
System.Threading.Tasks.Task
| Improve this Doc View Source

LoginAsync()

Declaration
public Task LoginAsync()
Returns
Type Description
System.Threading.Tasks.Task
| Improve this Doc View Source

LoginAsync(MegaApiClient.AuthInfos)

Declaration
public Task<MegaApiClient.LogonSessionToken> LoginAsync(MegaApiClient.AuthInfos authInfos)
Parameters
Type Name Description
MegaApiClient.AuthInfos authInfos
Returns
Type Description
System.Threading.Tasks.Task<MegaApiClient.LogonSessionToken>
| Improve this Doc View Source

LoginAsync(MegaApiClient.LogonSessionToken)

Declaration
public Task LoginAsync(MegaApiClient.LogonSessionToken logonSessionToken)
Parameters
Type Name Description
MegaApiClient.LogonSessionToken logonSessionToken
Returns
Type Description
System.Threading.Tasks.Task
| Improve this Doc View Source

LoginAsync(String, String, String)

Declaration
public Task<MegaApiClient.LogonSessionToken> LoginAsync(string email, string password, string mfaKey = null)
Parameters
Type Name Description
System.String email
System.String password
System.String mfaKey
Returns
Type Description
System.Threading.Tasks.Task<MegaApiClient.LogonSessionToken>
| Improve this Doc View Source

Logout()

Logout from Mega.co.nz service

Declaration
public void Logout()
Exceptions
Type Condition
System.NotSupportedException

Not logged in

| Improve this Doc View Source

LogoutAsync()

Declaration
public Task LogoutAsync()
Returns
Type Description
System.Threading.Tasks.Task
| Improve this Doc View Source

Move(INode, INode)

Change node parent

Declaration
public INode Move(INode node, INode destinationParentNode)
Parameters
Type Name Description
INode node

Node to move

INode destinationParentNode

New parent

Returns
Type Description
INode

Moved node

Exceptions
Type Condition
System.NotSupportedException

Not logged in

ApiException

Mega.co.nz service reports an error

System.ArgumentNullException

node or destinationParentNode is null

System.ArgumentException

node is not valid (only Directory and File are supported)

System.ArgumentException

parent is not valid (all types except File are supported)

| Improve this Doc View Source

MoveAsync(INode, INode)

Declaration
public Task<INode> MoveAsync(INode sourceNode, INode destinationParentNode)
Parameters
Type Name Description
INode sourceNode
INode destinationParentNode
Returns
Type Description
System.Threading.Tasks.Task<INode>
| Improve this Doc View Source

Rename(INode, String)

Declaration
public INode Rename(INode node, string newName)
Parameters
Type Name Description
INode node
System.String newName
Returns
Type Description
INode
| Improve this Doc View Source

RenameAsync(INode, String)

Declaration
public Task<INode> RenameAsync(INode sourceNode, string newName)
Parameters
Type Name Description
INode sourceNode
System.String newName
Returns
Type Description
System.Threading.Tasks.Task<INode>
| Improve this Doc View Source

Upload(Stream, String, INode, Nullable<DateTime>, Nullable<CancellationToken>)

Upload a stream on Mega.co.nz and attach created node to selected parent

Declaration
public INode Upload(Stream stream, string name, INode parent, DateTime? modificationDate = null, CancellationToken? cancellationToken = null)
Parameters
Type Name Description
System.IO.Stream stream

Data to upload

System.String name

Created node name

INode parent

Node to attach the uploaded file (all types except File are supported)

System.Nullable<System.DateTime> modificationDate

Custom modification date stored in the Node attributes

System.Nullable<System.Threading.CancellationToken> cancellationToken

CancellationToken used to cancel the action

Returns
Type Description
INode

Created node

Exceptions
Type Condition
System.NotSupportedException

Not logged in

ApiException

Mega.co.nz service reports an error

System.ArgumentNullException

stream or name or parent is null

System.ArgumentException

parent is not valid (all types except File are supported)

| Improve this Doc View Source

UploadAsync(Stream, String, INode, IProgress<Double>, Nullable<DateTime>, Nullable<CancellationToken>)

Declaration
public Task<INode> UploadAsync(Stream stream, string name, INode parent, IProgress<double> progress = null, DateTime? modificationDate = null, CancellationToken? cancellationToken = null)
Parameters
Type Name Description
System.IO.Stream stream
System.String name
INode parent
System.IProgress<System.Double> progress
System.Nullable<System.DateTime> modificationDate
System.Nullable<System.Threading.CancellationToken> cancellationToken
Returns
Type Description
System.Threading.Tasks.Task<INode>
| Improve this Doc View Source

UploadFile(String, INode, Nullable<CancellationToken>)

Upload a file on Mega.co.nz and attach created node to selected parent

Declaration
public INode UploadFile(string filename, INode parent, CancellationToken? cancellationToken = null)
Parameters
Type Name Description
System.String filename

File to upload

INode parent

Node to attach the uploaded file (all types except File are supported)

System.Nullable<System.Threading.CancellationToken> cancellationToken

CancellationToken used to cancel the action

Returns
Type Description
INode

Created node

Exceptions
Type Condition
System.NotSupportedException

Not logged in

ApiException

Mega.co.nz service reports an error

System.ArgumentNullException

filename or parent is null

System.IO.FileNotFoundException

filename is not found

System.ArgumentException

parent is not valid (all types except File are supported)

| Improve this Doc View Source

UploadFileAsync(String, INode, IProgress<Double>, Nullable<CancellationToken>)

Declaration
public Task<INode> UploadFileAsync(string filename, INode parent, IProgress<double> progress = null, CancellationToken? cancellationToken = null)
Parameters
Type Name Description
System.String filename
INode parent
System.IProgress<System.Double> progress
System.Nullable<System.Threading.CancellationToken> cancellationToken
Returns
Type Description
System.Threading.Tasks.Task<INode>

Events

| Improve this Doc View Source

ApiRequestFailed

Declaration
public event EventHandler<ApiRequestFailedEventArgs> ApiRequestFailed
Event Type
Type Description
System.EventHandler<ApiRequestFailedEventArgs>

Implements

IMegaApiClient
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2013-2024 - Gregoire Pailler - MegaApiClient 1.10.5