Comments (11)
Well Mega API allows to create nodes with same name. We can change CreateFolder method to throw if we try to create a folder with a name that already exist but it's a shame to introduce this kind of limitation.
I think it's client side responsibility to get the folder node or create it if it doesn't exist.
Another solution is to add a method GetOrCreateFolder but if there is already 2 folders with the same name, the method is unable to choose and will throw.
What do you think?
from megaapiclient.
Hi! I think it is very ambiguous to have 2 or more folders/files with the same name GetOrCreateFolder will be fine for me but not for others
You can give me some steps to implement that:create folder if it not exists or else to select the folder
another question : do I need to distribute Newtonsoft.Json.dll ?
thanks!
from megaapiclient.
I don't know VB but something like that should work:
Dim myFolder As INode = client.nodes.[FirstOrDefault](Function(n) n.Type = NodeType.Folder And n.Name = "Upload")
If myFolder = Nothing then
myFolder = client.CreateFolder("Upload", root)
End If
About Newtonsoft.Json.dll, you must distribute it with MegaApiClient
from megaapiclient.
good,it works with some little corrections:
Dim myFolder As INode = nodes.[FirstOrDefault](Function(n) n.Type = NodeType.Directory And n.Name = "upload") If myFolder Is Nothing Then myFolder = client.CreateFolder("upload", root) End If
thanks!
from megaapiclient.
Ok my skill in VB is not so good ;-)
from megaapiclient.
Any solution for C# on this?
from megaapiclient.
To create a folder on root if it doesn't exist:
var nodes = client.GetNodes(); // Retrieve all folders and files
var root = nodes.Single(n => n.Type == NodeType.Root); // Retrieve root node
// Search a folder with "folder" name under root
var myFolder = client.GetNodes(root).FirstOrDefault(n => n.Type == NodeType.Folder && n.Name == "folder");
// Create the "folder" if not found
if (myFolder == null)
{
myFolder = client.CreateFolder("folder", root);
}
from megaapiclient.
Thank you very much!
from megaapiclient.
wow man is magnific , thanks
from megaapiclient.
I think you should make it a Boolean parameter to the CreateFolder() function.
from megaapiclient.
I prefer to avoid having this kind of flag because I don't want to have to download all the nodes for this check in the CreateFolder() method. MegaApiClient is "stateless" in the sense it doesn't keep a cache of the nodes and cannot make any assumption about the existing nodes structure.
I think it's the library consumer task to refresh/maintain the nodes cache and decide based on its content if a folder needs to be created or not.
from megaapiclient.
Related Issues (20)
- Exception in UploadFile HOT 1
- Problem accessing MEGA API account HOT 3
- Add ability to attach thumbnails to image uploads HOT 1
- Possible To Get Progress On Get Nodes HOT 1
- Add sample to show how to retrieve folder contents recursively from parent folder
- publicly available node AccessDenied, when get info about node HOT 4
- How can I implement functions to collect more metadata?
- Unable to get download link for directory node HOT 2
- Contacts and shared folders support? Usage of owner IDs? Errors with attribute deserialization! HOT 1
- Resolving MEGA Account Blocking Issue When Uploading Files HOT 2
- MegaApiClient error when building Console App to native code HOT 1
- CG.Web.MegaApiClient.MegaApiClient.Login > Unable to cast object of type 'System.Int64' to type 'Newtonsoft.Json.Linq.JArray' HOT 3
- Problem with LoginAnonymous()
- What is the difference between `Task.Delay(retryDelay).Wait()` and `Thread.Sleep(retryDelay)` HOT 3
- Unable to load nodes due to too much memory consumption. HOT 4
- Attribute deserialization failed: Unexpected character encountered while parsing value: HOT 1
- Not returning new created folders HOT 4
- MegaApiClient is now in passive maintenance mode HOT 1
- Name is coming as NULL for files uploaded using 'CreateFileRequest'
- Erro DeleteAsync HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from megaapiclient.