鸿蒙开源组件——web端与app端文件传输

jacksky
发布于 2021-10-15 18:05
浏览
0收藏

FileTransfer

项目介绍

  • 项目名称:FileTransfer
  • 所属系列:openharmony的第三方组件适配移植
  • 功能:web端与app端文件传输
  • 项目移植状态:完成
  • 调用差异:因网络库限制 暂不支持断点续传功能以及文件传输速度无法控制
  • 开发版本:sdk6,DevEco Studio 2.2 Beta1
  • 基线版本:master分支

效果演示鸿蒙开源组件——web端与app端文件传输-鸿蒙开发者社区

使用说明:

该文件传输Demo基于AndServer服务器开发,分别依赖
com.gitee.chinasoft_ohos:AndserverApi:0.0.1-SNAPSHOT
com.gitee.chinasoft_ohos:AndserverAnnotation:0.0.1-SNAPSHOT
com.gitee.chinasoft_ohos:AndserverProcessor:0.0.1-SNAPSHOT

这三个依赖对应的源码分别在gitee的chinasoft3_ohos/AndServer的api、annotation、processor目录中。

具体调用api方法如下:

Server server = AndServer.webServer(context)
    .port(8080)
    .timeout(10, TimeUnit.SECONDS)
    .build();

// 开启服务.
server.startup();

...

// 关闭服务
server.shutdown();

http 动态接口的示例如下:

@RestController
@RequestMapping(path = "/user")
public class UserController {

    @PostMapping(path = "/upload", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    String upload(@RequestParam(name = "avatar") MultipartFile file) throws IOException {
        File localFile =  FileUtils.createRandomFile(file);
       ...
        return localFile.getAbsolutePath();
    }

    @PostMapping(path = "/delete", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    String delete(@RequestParam(name = "name") @RequestBody String name) throws IOException {
        File file = new File(MainAbilitySlice.path + "/" + name);
      
        return file;
    }

    @RequestMapping(
            path = "/fileList",
            method = {RequestMethod.PUT, RequestMethod.POST, RequestMethod.GET},
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE)ResponseBody download(HttpRequest request, HttpResponse response) throws IOException {
     
        return new StreamBody(FileUtils.fileToinputstream(fileEntity));

    }
}

测试信息

CodeCheck代码测试无异常

CloudTest代码测试无异常

病毒安全检测通过

当前版本demo功能与原组件基本无差异

版本迭代

  • 1.0.0

版权和许可信息

Copyright (c) 2018 CPPAlien

Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://github.com/CPPAlien/FileTransfer/blob/master/LICENSE

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

FileTransfer-master.zip 1.5M 29次下载
已于2021-10-15 18:05:33修改
收藏
回复
举报
回复
    相关推荐