目前单框架原生鸿蒙下的协议传输库适配较少,需要等待后续发力。
目前已知的第三方库:
仓库地址:ohos_napi · AtomGit_开放原子开源基金会代码托管平台
已经测试可用的功能:
直通车: atomgit.com/wysp2012/ohos_napi/blob/master/har/entry/src/main/ets/pages/Index.ets
import { AuthType, Client } from '@dove/webdav';
@Entry
@Component
struct Index {
@State message: string = 'Hello World';
build() {
Column() {
Text(this.message)
.maxLines(6)
.fontSize('20vp')
.fontWeight(FontWeight.Bold)
.textOverflow({ overflow: TextOverflow.Ellipsis })
Button('TEST WebDav')
.margin({ top: '12vp' })
.onClick(async () => {
try {
const client = new Client("https://dav.jianguoyun.com/dav/", "michael1995415@petalmail.com", 'agxc36j3uxn56iqh', AuthType.Basic);
await client.connect(true, true);
const files = await client.list('');
this.message += "files:" + files.length;
} catch (err) {
this.message = "error:" + err;
}
})
}
}
}
调用:
//获取路径下所有文件和文件夹信息
list(remotePath: string): Promise<Array<FileInfo>>
//获取文件流
get(remotePath: string): Promise<ArrayBuffer | null>
//获取文件并写入到指定路径下
writeTo(remotePath: string, filePath: string): Promise<boolean>
//上传文件到远程路径
put(remotePath: string, filePath: string): Promise<boolean>
//删除远端文件
delete(remotePath: string): Promise<boolean>
//移动远端文件
mv(sourcePath: string, targetPath: string): Promise<boolean>
//复制远端文件
cp(sourcePath: string, targetPath: string): Promise<boolean>
//创建文件夹
mkdir(remotePath: string): Promise<boolean>
//释放连接
close(): void
但经过实测,只有list成功了,而且对服务器的版本有要求,如果服务器返回405是不能正常返回列表的,服务器返回200可以正常返回列表。
put(远程路径,本地路径) 这个调用发生了数据传输,但是远程未收到,本地也报错,报错提示native code,应该是上层so库没有详细的错误提示导致。
该生态尚不完善,需要各位同仁继续用爱发电。

@dove/webdav(V0.2.3)\],是一个 OpenHarmony/HarmonyOS webdav库,基于 ohos-rs 开发,支持使用 API13 以上。