1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-06 17:33:18 +00:00

fix upload image (#4766)

This commit is contained in:
songjiaqi1
2020-12-24 15:20:01 +08:00
committed by GitHub
parent dd0515cd99
commit 6e0b04ccfc

View File

@@ -77,33 +77,10 @@ class EditorApi {
const url = this.serviceUrl + '/lib/' + repoID + '/file/images/auto-upload/' + fileName + '?raw=1';
return url;
}
uploadImage = (imageFile) => {
return (
seafileAPI.getFileServerUploadLink(repoID, dirPath).then((res) => {
let uploadLinkComponent = res.data;
const uploadLink = uploadLinkComponent + '?ret-json=1';
const name = getImageFileNameWithTimestamp();
const blob = imageFile.slice(0, -1, 'image/png');
const newFile = new File([blob], name, {type: 'image/png'});
const formData = new FormData();
formData.append('parent_dir', '/');
formData.append('relative_path', 'images/auto-upload');
formData.append('file', newFile);
return {uploadLink, formData};
}).then(({ uploadLink, formData}) => {
return seafileAPI.uploadImage(uploadLink, formData);
}).then ((res) => {
let resArr = res.data[0];
let filename = resArr.name;
return this._getImageURL(filename);
})
);
}
uploadLocalImage = (imageFile) => {
return (
seafileAPI.getFileServerUploadLink(repoID, dirPath).then((res) => {
seafileAPI.getFileServerUploadLink(repoID, '/').then((res) => {
const uploadLink = res.data + '?ret-json=1';
const name = getImageFileNameWithTimestamp();
const newFile = new File([imageFile], name, {type: imageFile.type});