基于resteasy,Base64码上传文件
package com.xgt.controller.bs; import com.xgt.bean.bs.VersionBean; import com.xgt.common.BaseController; import com.xgt.common.PcsResult; import com.xgt.service.bs.VersionService; import com.xgt.util.ConstantsUtil; import com.xgt.util.FileUtils; import com.xgt.util.OssUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import javax.ws.rs.FormParam; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import java.io.FileNotFoundException; import java.io.IOException; /** * Created by Administrator on 2017/9/14. */ @Controller @Path("/installationPackageServerApi") public class InstallationPackageServerApiController extends BaseController { @Autowired private VersionService versionService; /** * 上传安装包到服务器 * @param installationPackage * @param installationPackageName * @return * @throws IOException */ @POST @Path("/uploadInstallationPackage") @Produces(MediaType.APPLICATION_JSON) public PcsResult uploadInstallationPackage(@FormParam("accessToken") String accessToken,@FormParam("installationPackage") String installationPackage , @FormParam("installationPackageName") String installationPackageName,@FormParam("versionName") String versionName) throws IOException { byte[] encodeBase64 = FileUtils.getZip(installationPackage, installationPackageName); VersionBean versionBean = new VersionBean(); versionBean.setAccessToken(accessToken); versionBean.setInstallationPackageName(installationPackageName); versionBean.setInstallationPackage(encodeBase64); uploadFile(versionBean); return newResult(true); } private void uploadFile(VersionBean version) throws FileNotFoundException { if(version.getInstallationPackage().length>0){ // 上传到图片服务器 OssUtil oss=new OssUtil(accessKeyId, accessKeySecret, endpoint,bucketName); //图片 String InstallationPackageName = version.getInstallationPackageName(); oss.putObject(ConstantsUtil.Folder_PACKAGE_PATH+ConstantsUtil.FILE_SEPARATOR +InstallationPackageName, version.getInstallationPackage()); version.setInstallationPackageName(ConstantsUtil.Folder_PACKAGE_PATH+ConstantsUtil.FILE_SEPARATOR +InstallationPackageName); versionService.insertVersion(version); Integer versionId = versionService.gainVersionId(version); version.setVersionId(versionId); versionService.insertInstallationPackage(version); } } }
作者:Rest探路者
出处:http://www.cnblogs.com/Java-Starter/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意请保留此段声明,请在文章页面明显位置给出原文连接
Github:https://github.com/cjy513203427
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?