java本地上传图片到阿里云服务器的共享文件夹
来源:互联网 发布:淘宝晒单福利图2000p 编辑:程序博客网 时间:2024/05/17 02:59
阿里云服务器需要开放139,445端口,但是这样做极不安全,容易被黑客攻击。
参考链接 点击打开链接
import jcifs.smb.SmbFile;import jcifs.smb.SmbFileOutputStream;
public boolean uploadPic(MultipartFile file) {InputStream in = null;OutputStream out = null;try {String host = "47.92.XXX.XX";// 远程服务器的地址String username = "Administrator";// 用户名String password = "XXXXXXXXXX";// 密码String path = "/Users/Administrator/Desktop/upload/";// 远程服务器共享文件夹名称String fileName = file.getOriginalFilename();String type = fileName.indexOf(".") != -1? fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()): null;if (type != null) {if ("GIF".equals(type.toUpperCase()) || "PNG".equals(type.toUpperCase())|| "JPG".equals(type.toUpperCase())) {String trueFileName = String.valueOf(System.currentTimeMillis()) + fileName;String remoteUrl = "smb://" + username + ":" + password + "@" + host + path+ (path.endsWith("/") ? "" : "/");SmbFile remoteFile = new SmbFile(remoteUrl + "/" + trueFileName);remoteFile.connect();in = new BufferedInputStream(file.getInputStream());out = new BufferedOutputStream(new SmbFileOutputStream(remoteFile));byte[] buffer = new byte[4096];int len = 0;while ((len = in.read(buffer, 0, buffer.length)) != -1) {out.write(buffer, 0, len);}out.flush();}}} catch (Exception e) {String msg = "发生错误:" + e.getLocalizedMessage();System.out.println(msg);} finally {try {if (out != null) {out.close();}if (in != null) {in.close();}} catch (Exception e) {}}return false;}
阅读全文
0 0
- java本地上传图片到阿里云服务器的共享文件夹
- 读取阿里云服务器图片到本地
- JAVA,本地上传图片到服务器
- 图片批量上传到阿里云服务器
- java从服务器上传本地图片到图片服务器
- java从服务器上传本地图片到图片服务器
- java上传图片到阿里云
- wordpress网站从本地上传到阿里云服务器
- bootstrap-wysiwyg中JS控件富文本中的图片由本地上传到服务器(阿里云、七牛、自己的数据库)
- java中怎么将本地图片上传到服务器上
- java上传图片到文件夹
- java实现上传图片上传到阿里云
- JAVA 影像上传至本地/服务器的某一文件夹
- 上传图片到阿里云
- 从本地上传整个文件夹到hdfs的java程序
- java上传文件到共享文件夹
- struts2 上传本地图片到服务器
- Android上传图片到本地服务器
- Android调用腾讯地图app导航
- tensorflow 常用语句
- ros 坐标系
- JSON.parse()和JSON.stringify()
- <小田吃饺子> LINUX:Contos7.0 / 7.2 LAMP+R 下载安装Redis篇
- java本地上传图片到阿里云服务器的共享文件夹
- RabbitMQ原理与相关操作(二)
- 中频滤波器和镜像抑制滤波器
- 28个Github上最火的机器学习开源项目
- 两对象间的属性复制
- Java学习路线
- 使用Jenkins配置Git+Maven的自动化构建
- 二叉树中和为某一值的路径
- 如何控制使用thymeleaf不在控制台打印日志