-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(upload): 抽离上传本地服务器方法到utils里,可被单独调用 (#472)
- Loading branch information
Showing
3 changed files
with
32 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type {UploadRequestOptions} from "element-plus"; | ||
|
||
/** | ||
* MineAdmin is committed to providing solutions for quickly building web applications | ||
* Please view the LICENSE file that was distributed with this source code, | ||
* For the full copyright and license information. | ||
* Thank you very much for using MineAdmin. | ||
* | ||
* @Author X.Mo<[email protected]> | ||
* @Link https://github.com/mineadmin | ||
*/ | ||
export function uploadLocal(options: UploadRequestOptions, url?: string = '/admin/attachment/upload', key?: string = 'file') { | ||
const upload = (formData: FormData) => { | ||
return useHttp().post(url, formData) | ||
} | ||
|
||
return new Promise((resolve, reject) => { | ||
const formData = new FormData() | ||
formData.append(key, options.file) | ||
upload(formData).then((res: Record<string, any>) => { | ||
res.code === 200 ? resolve(res) : reject(res) | ||
}).catch((err) => { | ||
reject(err) | ||
}) | ||
}) | ||
} |