{"id":23583962,"url":"https://github.com/alamhubb/transfer-files-between-dubbo","last_synced_at":"2025-11-02T23:30:38.324Z","repository":{"id":118176772,"uuid":"145211557","full_name":"alamhubb/Transfer-files-between-Dubbo","owner":"alamhubb","description":"dubbo服务之间传输File文件，将File转成byte array 传输","archived":false,"fork":false,"pushed_at":"2018-08-18T11:13:31.000Z","size":47344,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-27T02:18:39.752Z","etag":null,"topics":["dubbo","file","transfer"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alamhubb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-08-18T10:38:26.000Z","updated_at":"2021-06-08T07:23:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"4f492834-7cb6-4c1d-8a27-fcd6d6b6fa69","html_url":"https://github.com/alamhubb/Transfer-files-between-Dubbo","commit_stats":null,"previous_names":["alamhubb/transfer-files-between-dubbo"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alamhubb%2FTransfer-files-between-Dubbo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alamhubb%2FTransfer-files-between-Dubbo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alamhubb%2FTransfer-files-between-Dubbo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alamhubb%2FTransfer-files-between-Dubbo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alamhubb","download_url":"https://codeload.github.com/alamhubb/Transfer-files-between-Dubbo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239403519,"owners_count":19632603,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dubbo","file","transfer"],"created_at":"2024-12-27T02:18:44.059Z","updated_at":"2025-11-02T23:30:38.279Z","avatar_url":"https://github.com/alamhubb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dubbo服务之间传输File Transfer files between Dubbo \n\n#### 项目介绍\n\ndubbo之间传输File文件，将File转成byte数组传输，附上代码\n\n项目没有使用zokkeeper\n\n先启动服务端代码，之后才能启动消费端，否则的话是无法访问服务端的，\n\n启动项目后输入http://localhost:8080/1 \n\n点击页面中的小相机按钮上传图片，然后点击上传按钮\n\n图片则会上传到电脑的 D:\\file\\a.jpg\n\n\n### 参考\n\n\ndubbo-spring-boot-starter使用的是阿里官方整合的springboot框架\n\nhttps://github.com/alibaba/dubbo-spring-boot-starter/blob/master/README_zh.md\n\ndubbo-spring-boot-starter使用方式参考了以下文章\n\nhttps://blog.csdn.net/qq_36890499/article/details/80858663\n\nJava 文件和byte数组转换 参考：\n\nhttps://www.cnblogs.com/kgdxpr/p/3595518.html\n\n\n\n### 代码部分：\n\n前端部分有很多没有用的代码，不需要关注，\n\n重要代码\n\n前端：\n\n使用了vue和mint-ui\n\n### 首页代码\n\n\n### html：\n\n\n相机按钮\n\n        \u003clabel for=\"img\" class=\"icon iconfont icon-add\" style=\"font-size: 80px;\"\u003e\u003c/label\u003e\n大加号上传图片样式\n\n        \u003cinput id=\"img\" type=\"file\" accept=\"image/*\" style=\"opacity: 0;width: 0;height: 0\" @change=\"upload\"\u003e\n上传按钮\n\n        \u003cmt-button style=\"margin-left: 50px\" @click=\"postImgs\"\u003e上传\u003c/mt-button\u003e\n\n### js:\n\n\n    data: {     imgs: [],//图片文件数组\n            talkImgs: [],//图片名数组\n            index: 0 //图片数量 好像没用到大写尴尬\n        },\n    methods: {\n            \n            //上传图片后出发的方法\n            upload(obj) {\n                const reader = new FileReader()\n                reader.readAsDataURL(obj.target.files[0]);\n                reader.onload = function () {\n                    app.imgs.push({img: obj.target.files[0], src: this.result})\n                    app.talkImgs.push({imgSrc: obj.target.files[0].name})\n                    app.index++\n                }\n            },\n            //点击上传按钮执行的方法\n            postImgs() {\n                let formData = new FormData();\n                let imgs = []\n                for (let img of this.imgs) {\n                    imgs.push(img.img)\n                    formData.append(\"files\", img.img)\n                }\n                axios.post('/upload', formData)\n                    .then(response =\u003e {\n                        console.log(response.data);\n                    })\n                    .catch(function (error) {\n                        alert(\"上传失败\");\n                        console.log(error);\n                    });\n            }\n\n### java api:\n\n\n    public interface DemoService {\n\n    String sayHello(String name);\n\n    String convertFile(byte[] bytes);\n    }\n\n\n### java 消费端\n\n\n    @Controller\n    public class IndexController {\n    @RequestMapping(\"1\")\n    public String index() {\n        System.out.println(\"123\");\n        return \"index\";\n    }\n    }\n\n    @RestController\n    public class UploadController {\n    @Reference(version = \"1.0.0\",\n            application = \"${dubbo.application.id}\",\n            url = \"dubbo://localhost:12345\")\n    private DemoService demoService;\n\n    @PostMapping(\"upload\")\n    public String upload(MultipartFile[] files) {\n        for (MultipartFile file : files) {\n            if (Objects.isNull(file) || file.isEmpty()) {\n                return \"文件为空，请重新上传\";\n            }\n            try {\n                System.out.println(file.getName());\n                System.out.println(file.getSize());\n                byte[] bytes = file.getBytes();\n                return demoService.convertFile(bytes);\n            } catch (IOException e) {\n                e.printStackTrace();\n                return \"失败\";\n            }\n        }\n        return \"失败\";\n    }\n    }\n\n### java服务端：\n\n\n    @Service(\n        version = \"1.0.0\",\n        application = \"${dubbo.application.id}\",\n        protocol = \"${dubbo.protocol.id}\",\n        registry = \"${dubbo.registry.id}\"\n    )\n    public class DemoServiceImpl implements DemoService {\n\n    @Override\n    public String sayHello(String name) {\n        return \"Hello, \" + name + \" (from Spring Boot)\";\n    }\n\n    @Override\n    public String convertFile(byte[] bytes) {\n        System.out.println(bytes);\n        System.out.println(123);\n        BufferedOutputStream bos = null;\n        FileOutputStream fos = null;\n        File file = null;\n        try {\n            String filePath = \"d:/file\";\n            File dir = new File(filePath);\n            if (!dir.exists() || !dir.isDirectory()) {//判断文件目录是否存在\n                dir.mkdirs();\n            }\n            file = new File(filePath + \"/a.jpg\");\n            fos = new FileOutputStream(file);\n            bos = new BufferedOutputStream(fos);\n            bos.write(bytes);\n            System.out.println(file.getName());\n            System.out.println(file.length());\n            System.out.println(file.toPath());\n        } catch (IOException e) {\n            e.printStackTrace();\n            return \"失败\";\n        } finally {\n            if (bos != null) {\n                try {\n                    bos.close();\n                } catch (IOException e1) {\n                    e1.printStackTrace();\n                }\n            }\n            if (fos != null) {\n                try {\n                    fos.close();\n                } catch (IOException e1) {\n                    e1.printStackTrace();\n                }\n            }\n        }\n        return \"成功\";\n    }\n\n    }\n\n### pom文件\n\n\n```\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cproject xmlns=\"http://maven.apache.org/POM/4.0.0\"\n         xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n         xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\"\u003e\n    \u003cmodelVersion\u003e4.0.0\u003c/modelVersion\u003e\n\n    \u003cgroupId\u003ecom.qky\u003c/groupId\u003e\n    \u003cartifactId\u003edubbo-starter-demo\u003c/artifactId\u003e\n    \u003cpackaging\u003epom\u003c/packaging\u003e\n    \u003cversion\u003e0.0.1-SNAPSHOT\u003c/version\u003e\n\n    \u003cparent\u003e\n        \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n        \u003cartifactId\u003espring-boot-starter-parent\u003c/artifactId\u003e\n        \u003cversion\u003e2.0.4.RELEASE\u003c/version\u003e\n        \u003crelativePath/\u003e \u003c!-- lookup parent from repository --\u003e\n    \u003c/parent\u003e\n\n    \u003cmodules\u003e\n        \u003cmodule\u003edemo-api\u003c/module\u003e\n        \u003cmodule\u003edemo-consumer\u003c/module\u003e\n        \u003cmodule\u003edemo-provider\u003c/module\u003e\n    \u003c/modules\u003e\n\n    \u003cproperties\u003e\n        \u003cproject.build.sourceEncoding\u003eUTF-8\u003c/project.build.sourceEncoding\u003e\n        \u003cproject.reporting.outputEncoding\u003eUTF-8\u003c/project.reporting.outputEncoding\u003e\n        \u003cjava.version\u003e1.8\u003c/java.version\u003e\n    \u003c/properties\u003e\n\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n            \u003cartifactId\u003espring-boot-starter-web\u003c/artifactId\u003e\n        \u003c/dependency\u003e\n\n        \u003cdependency\u003e\n            \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n            \u003cartifactId\u003espring-boot-starter-test\u003c/artifactId\u003e\n            \u003cscope\u003etest\u003c/scope\u003e\n        \u003c/dependency\u003e\n\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.alibaba.boot\u003c/groupId\u003e\n            \u003cartifactId\u003edubbo-spring-boot-starter\u003c/artifactId\u003e\n            \u003cversion\u003e0.2.0\u003c/version\u003e\n        \u003c/dependency\u003e\n\n        \u003cdependency\u003e\n            \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n            \u003cartifactId\u003espring-boot-starter-thymeleaf\u003c/artifactId\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n\n    \u003cbuild\u003e\n        \u003cplugins\u003e\n            \u003cplugin\u003e\n                \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n                \u003cartifactId\u003espring-boot-maven-plugin\u003c/artifactId\u003e\n            \u003c/plugin\u003e\n        \u003c/plugins\u003e\n    \u003c/build\u003e\n\n\u003c/project\u003e\n```\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falamhubb%2Ftransfer-files-between-dubbo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falamhubb%2Ftransfer-files-between-dubbo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falamhubb%2Ftransfer-files-between-dubbo/lists"}