timestee / dart-webdav

A Easy WebDAV Client in Dart
https://github.com/timestee/dart-webdav
The Unlicense
28 stars 14 forks source link

Example for editing a file in situ ? #1

Open paul-hammant opened 5 years ago

paul-hammant commented 5 years ago

Say there's a resource foo/bar.txt and it is only a line or two of CR-delimited text. Can a simple Flutter+Dart app show that being GET from the server, then PUT back to the same server after editing?

That's different to a download/upload scenario :)

timestee commented 5 years ago

Actually, there is not so much difference i think. this lib is using in our Flutter App to sync data from remote web storage and local db on mobile device.

// downlad
List<String> uuids = new List<String>();
List<webdav.FileInfo> files = await webDav.ls("/");
for (webdav.FileInfo file in files) {
    if(file.isDict){
      continue;
    }
    // we just use the uuid as file name in debug mode
    uuids.add(file.name.substring(file.name.lastIndexOf("/")));
}
for(String uuid in uuids) {
    String data = await webDav.downloadToBinaryString(uuid);
    // then store the data to local file or db
    // ... 
}

// upload
var dataMap = Map<String, dynamic>();
// dataMap is the data from local db, or from local file
List<int> list = json.encode(dataMap).codeUnits;
webDav.upload(Uint8List.fromList(list), rid);

Do you feel that we need an example? Perhaps the API is pretty much self-explanatory now.

paul-hammant commented 5 years ago

Fantastic!!!!!

timestee commented 5 years ago

@paul-hammant i am new to dart,so appreciate if you could give me any suggestion or help me to improve it. Test and example are on the way.

paul-hammant commented 5 years ago

So how about a Flutter app with a single textfield. The contents of the textfield come from a GET to (say) http://localhost:8000/textfield.txt. When the item is edited, the mini app does a PUT of the same resource back to the same endpoint. That's the smallest DAV using UI I can think about.

There's no such thing as a single-sourcefile flutter app, but the code for the get widget with inline usage of dart-webdav could be shown inlined in the README.

Otherwise the app goes into examples/ in this repo, with it's own README

Here's a tiny server that can handle PUT and be used in testing of the app - https://gist.github.com/fabiand/5628006