Flutter写了个webdav客户端插件,支持常用文件操作
webdav_client
- https://pub.dev/packages/webdav_client
- 使用 dio 作为 http 网络请求库,主要是方便后续的断点续传功能扩展
##主要功能
- support
Basic/Digest
authentication - common settings
- read dir
- make dir
- delete
- rename
- copy
- download file
- upload file
- cancel request
Todo
- Upload support for break uploads
- Download support for breakdowns
Usage
First of all you should create client
instance using newClient()
function:
var client = webdav.newClient(
'http://localhost:6688/',
user: 'flyzero',
password: '123456',
debug: true,
);
Common settings
// Set the public request headers
client.setHeaders({'accept-charset': 'utf-8'});
// Set the connection server timeout time in milliseconds.
client.setConnectTimeout(8000);
// Set send data timeout time in milliseconds.
client.setSendTimeout(8000);
// Set transfer data time in milliseconds.
client.setReceiveTimeout(8000);
// Test whether the service can connect
try {
await client.ping();
} catch (e) {
print('$e');
}
Read all files in a folder
var list = await client.readDir('/');
list.forEach((f) {
print('${f.name} ${f.path}');
});
// can sub folder
var list2 = await client.readDir('/sub/sub/folder');
list2.forEach((f) {
print('${f.name} ${f.path}');
});
Create folder
await client.mkdir('/新建文件夹');
// Recursively create folders
await client.mkdirAll('/new folder/new folder2');
Remove a folder or file
If you remove the folder, some webdav services require a '/' at the end of the path.
// Delete folder
await client.remove('/new folder/new folder2/');
// Delete file
await client.remove('/new folder/新建文本文档.txt');
Rename a folder or file
If you rename the folder, some webdav services require a '/' at the end of the path.
// Rename folder
await client.rename('/新建文件夹 /', '/新建文件夹 2/', true);
// Rename file
await client.rename('/新建文件夹 2/test.dart', '/新建文件夹 2/test2.dart', true);
Copy a file / folder from A to B
If copied the folder (A > B), it will copy all the contents of folder A to folder B.
Some webdav services have been tested and found to delete the original contents of the B folder!!!
// Copy all the contents of folderA to folder B
await client.copy('/folder/folderA/', '/folder/folderB/', true);
// Copy file
await client.copy('/folder/aa.png', '/folder/bb.png', true);
Download file
// download bytes
await client.read('/folder/folder/openvpn.exe');
// download 2 local file
await client.read2File(
'/folder/vpn.exe', 'C:/Users/xxx/vpn2.exe');
Upload file
// upload local file 2 remote file
await client.writeFromFile(
'C:/Users/xxx/vpn.exe', '/f/vpn2.exe');
Cancel request
CancelToken cancel = CancelToken();
// Supports most methods
client.mkdir('/新建文件夹', cancel)
.catchError((err) {
prints(err.toString());
});
// in other
cancel.cancel('reason')
Flutter写了个webdav客户端插件,支持常用文件操作
更多关于Flutter写了个webdav客户端插件,支持常用文件操作的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter写了个webdav客户端插件,支持常用文件操作的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
很高兴看到你开发了一个基于Flutter的WebDAV客户端插件,并支持常用的文件操作。以下是一些专业意见和可能的改进方向:
首先,你的插件对于需要在多个平台上实现文件同步和共享的应用来说,是一个非常有价值的工具。WebDAV(Web-based Distributed Authoring and Versioning)是一种基于HTTP的协议,它允许用户编辑和管理远程服务器上的文件,因此你的插件能够跨平台工作,对于开发者来说是一个很大的便利。
在插件的功能上,建议你可以进一步扩展和优化。例如,除了基本的文件创建、读取、更新和删除操作外,还可以考虑增加对文件夹的操作(如创建、删除文件夹),以及对文件属性的修改(如修改文件权限、时间戳等)。这些功能将使你的插件更加完善和实用。
此外,在插件的性能和稳定性方面也需要关注。确保在各种网络环境下,插件都能稳定地工作,并且能够快速响应用户的操作。同时,也需要对插件进行充分的测试,以确保其没有严重的安全漏洞。
最后,建议你在文档和示例代码方面下功夫。提供清晰、详细的文档和示例代码,将有助于其他开发者更好地理解和使用你的插件。
总的来说,你的Flutter WebDAV客户端插件是一个非常有潜力的项目。希望你在未来的开发中,能够不断完善和优化插件的功能和性能,为更多的开发者提供便利。