|
@ -5,6 +5,7 @@ import com.yihu.fastdfs.FastDFSUtil;
|
|
|
import it.sauronsoftware.jave.*;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
@ -15,10 +16,11 @@ import java.io.InputStream;
|
|
|
* 文件处理工具类
|
|
|
* @author huangwenjie
|
|
|
*/
|
|
|
@Component
|
|
|
public class FileUtil {
|
|
|
|
|
|
@Autowired
|
|
|
private FastDFSUtil fastDFSHelper;
|
|
|
public FastDFSUtil fastDFSHelper;
|
|
|
|
|
|
public void changeToMp3(String sourcePath, String targetPath) {
|
|
|
File source = new File(sourcePath);
|
|
@ -49,15 +51,16 @@ public class FileUtil {
|
|
|
*/
|
|
|
|
|
|
|
|
|
public String copyTempVoice(String voices_Path,String fastdfs_file_url) throws Exception {
|
|
|
public String copyTempVoice(String voices_Path,String fastdfs_file_url) throws Exception {
|
|
|
// 文件保存的临时路径
|
|
|
FastDFSUtil fastDFSUtil = new FastDFSUtil();
|
|
|
String fileUrls = "";
|
|
|
File f = new File(voices_Path);
|
|
|
if (f.exists()) {
|
|
|
String fileName = f.getName();
|
|
|
InputStream in = new FileInputStream(f);
|
|
|
ObjectNode result = fastDFSUtil.upload(in, fileName.substring(fileName.lastIndexOf(".") + 1), "");
|
|
|
//得到文件类型
|
|
|
String fileType = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
|
ObjectNode result = fastDFSHelper.upload(in, fileType, "");
|
|
|
in.close();
|
|
|
if (result != null) {
|
|
|
fileUrls += (StringUtils.isEmpty(fileUrls) ? "" : ",") + fastdfs_file_url
|
|
@ -79,7 +82,6 @@ public class FileUtil {
|
|
|
public String copyTempImage(String files,String tempPath) throws Exception {
|
|
|
// 文件保存的临时路径
|
|
|
String[] fileArray = files.split(",");
|
|
|
FastDFSUtil fastDFSUtil = new FastDFSUtil();
|
|
|
String fileUrls = "";
|
|
|
for (String file : fileArray) {
|
|
|
File f = new File(tempPath + file);
|
|
@ -87,7 +89,7 @@ public class FileUtil {
|
|
|
if (f.exists()) {
|
|
|
String fileName = f.getName();
|
|
|
InputStream in = new FileInputStream(f);
|
|
|
ObjectNode result = fastDFSUtil.upload(in, fileName.substring(fileName.lastIndexOf(".") + 1), "");
|
|
|
ObjectNode result = fastDFSHelper.upload(in, fileName.substring(fileName.lastIndexOf(".") + 1), "");
|
|
|
in.close();
|
|
|
if (result != null) {
|
|
|
//1.3.7去掉前缀
|