You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.2 KiB
71 lines
2.2 KiB
/*
|
|
* Copyright (c) 2019. 黄钰朝
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
package com.hyc.wechat.util;
|
|
|
|
import com.hyc.wechat.exception.ServiceException;
|
|
import com.hyc.wechat.model.po.Chat;
|
|
import com.hyc.wechat.model.po.User;
|
|
|
|
import javax.servlet.ServletException;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.Part;
|
|
import java.io.IOException;
|
|
|
|
import static com.hyc.wechat.util.UUIDUtils.getUUID;
|
|
|
|
/**
|
|
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
|
* @program wechat
|
|
* @description 用于上传文件
|
|
* @date 2019-04-19 13:31
|
|
*/
|
|
public class UploadUtils {
|
|
|
|
|
|
/**
|
|
* 用于上传一个文件,返回该文件的文件名(写入photo文件夹)
|
|
*
|
|
* @return String 存储的文件名
|
|
* @name toPhotoName
|
|
* @notice none
|
|
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
|
* @date 2019/4/19
|
|
*/
|
|
public static String toPhotoName(Part part) throws IOException {
|
|
String head = part.getHeader("Content-Disposition");
|
|
String filename = getUUID() + head.substring(head.lastIndexOf("."), head.lastIndexOf("\""));
|
|
part.write("photo/"+filename);
|
|
return filename;
|
|
}
|
|
/**
|
|
* 用于上传一个文件,返回该文件的文件名(写入file文件夹)
|
|
*
|
|
* @return String 存储的文件名
|
|
* @name toFileName
|
|
* @notice none
|
|
* @author <a href="mailto:kobe524348@gmail.com">黄钰朝</a>
|
|
* @date 2019/5/14
|
|
*/
|
|
public static String toFileName(Part part) throws IOException {
|
|
String head = part.getHeader("Content-Disposition");
|
|
String filename = getUUID() + head.substring(head.lastIndexOf("."), head.lastIndexOf("\""));
|
|
part.write("file/"+filename);
|
|
return filename;
|
|
}
|
|
|
|
}
|