
回复
添加资源
添加资源将有机会获得更多曝光,你也可以直接关联已上传资源
去关联
该文件传输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功能与原组件基本无差异
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.