Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not returning new created folders #241

Open
alexandredutra opened this issue May 17, 2024 · 4 comments
Open

Not returning new created folders #241

alexandredutra opened this issue May 17, 2024 · 4 comments

Comments

@alexandredutra
Copy link

I am using the component to perform file uploads. I am logging in, creating a folder, and uploading the files to folders. Everything is working perfectly. The folders and files created appear on the online platform correctly. However, minutes later, when I make a new access and retrieve the nodes, the folders I created do not appear in the list of nodes. On the online platform, even when I create a folder and then try to access it, it also does not appear in the nodes. Could someone help me with this issue?

MegaApiClient Version:1.10.4

@gpailler
Copy link
Owner

Hello,

Could you provide a snippet of the code? The created folder appears in the list returned by GetNodes() when called immediately after the upload. However, it does not appear if you invoke GetNodes() on a new instance. Is this correct?

@alexandredutra
Copy link
Author

alexandredutra commented May 20, 2024

Hi, tanks for the answer this is the test code, the code runs ok .. but after first call... the folder exists codes always return false because the folder created previously not return on nodes...

var client = new MegaApiClient();

client.Login(Program.Parametros.GetSetting("Email"), Program.Parametros.GetSetting("Password"));

var nodes = client.GetNodesAsync().Result;

var root = nodes.Single(x => x.Type == NodeType.Root);

nodes = client.GetNodes(root);

IEnumerable onlineFolders = nodes.Where(x => x.Type == NodeType.Directory && x.ParentId == root.Id);

INode myFolder;

if (onlineFolders.Any(p => p.Name.ToLower() == Program.Parametros.GetSetting("OnlineFolder").ToLower()))
myFolder = onlineFolders.First(p => p.Name.ToLower() == Program.Parametros.GetSetting("OnlineFolder").ToLower());
else
myFolder = client.CreateFolder(Program.Parametros.GetSetting("OnlineFolder"), root);

var myFile = client.UploadFile(e.FullPath, myFolder);

client.Logout();

@gpailler
Copy link
Owner

I'm not sure to perfectly understand your scenario. You mean that the folder is not found when this snippet is called a second time?
Could you try the following code? It creates the folder if it doesn't exist, and it fetches the nodes again to ensure the folder exists.

    MegaApiClient client = new MegaApiClient();
    client.Login(Program.Parametros.GetSetting("Email"), Program.Parametros.GetSetting("Password"));

    INode[] nodes = client.GetNodes().ToArray();
    INode root = nodes.Single(x => x.Type == NodeType.Root);

    string folderName = Program.Parametros.GetSetting("OnlineFolder").ToLower();
    Func<INode, bool> folderExists = x => x.Type == NodeType.Directory && x.ParentId == root.Id && x.Name == folderName;

    // Search for the folder or create it
    INode folderNode = nodes.FirstOrDefault(folderExists);
    if (folderNode == null)
    {
        folderNode = client.CreateFolder(folderName, root);
    }

    // Retrieve the nodes again and search for the folder
    nodes = client.GetNodes().ToArray();
    if (nodes.Any(folderExists) == false)
    {
        throw new Exception("Folder not found");
    }

    client.Logout();

@alexandredutra
Copy link
Author

Hi, tks for the answer, i'm tested with your code block and tested with other folder name but in all cases the folder is created online but allways returning Folder Not Found... =/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants