Commit 7b829400 authored by yyh's avatar yyh

refactor:提取获取文件后缀函数

parent 0f58441a
import axios from '@/utils/http';
const base = process.env.VUE_APP_SERVER + '/file';
function getFileSuffix(file: File) {
const fileName = file.name;
const index = fileName.lastIndexOf('.');
return fileName.substr(index + 1);
}
export default {
upload(file: File, cb: (progressEvent: any) => void = (progressEvent: any) => progressEvent) {
const suffix = getFileSuffix(file);
const formData = new FormData();
const filename = file.name;
const index = filename.lastIndexOf('.');
const suffix = filename.substr(index + 1);
formData.append('file_data', file);
return axios({
url: `${base}/upload?file_type=${suffix}`,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment