mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-04 05:10:19 +08:00
Add UploadFile() API.
This commit is contained in:
@ -18,6 +18,7 @@ import "cropperjs/dist/cropper.css";
|
||||
import * as Setting from "./Setting";
|
||||
import {Button, Row, Col, Modal} from 'antd';
|
||||
import i18next from "i18next";
|
||||
import * as UserBackend from "./backend/UserBackend";
|
||||
|
||||
export const CropperDiv = (props) => {
|
||||
const [image, setImage] = useState("");
|
||||
@ -25,7 +26,7 @@ export const CropperDiv = (props) => {
|
||||
const [visible, setVisible] = React.useState(false);
|
||||
const [confirmLoading, setConfirmLoading] = React.useState(false);
|
||||
const {title} = props;
|
||||
const {targetFunction} = props;
|
||||
const {user} = props;
|
||||
const {buttonText} = props;
|
||||
let uploadButton;
|
||||
|
||||
@ -54,7 +55,8 @@ export const CropperDiv = (props) => {
|
||||
return false;
|
||||
}
|
||||
// Setting.showMessage("success", "uploading...");
|
||||
targetFunction(canvas.toDataURL());
|
||||
const userId = `${user.owner}/${user.name}`;
|
||||
UserBackend.uploadFile("avatar", userId, canvas.toDataURL());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -76,10 +76,10 @@ export function getAffiliationOptions(url, code) {
|
||||
}).then(res => res.json());
|
||||
}
|
||||
|
||||
export function uploadAvatar(avatar) {
|
||||
export function uploadFile(folder, subFolder, file) {
|
||||
let formData = new FormData();
|
||||
formData.append("avatarfile", avatar);
|
||||
fetch(`${Setting.ServerUrl}/api/upload-avatar`, {
|
||||
formData.append("file", file);
|
||||
fetch(`${Setting.ServerUrl}/api/upload-file?folder=${encodeURIComponent(folder)}&subFolder=${encodeURIComponent(subFolder)}`, {
|
||||
body: formData,
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
|
Reference in New Issue
Block a user