增加文件系统存储功能,修复上传功能
Change-Id: I7b76c0a78fa0a02018fa76e932d283e29b35d4be
diff --git a/Merge/front/src/api/posts_wzy.js b/Merge/front/src/api/posts_wzy.js
index d901500..4992f95 100644
--- a/Merge/front/src/api/posts_wzy.js
+++ b/Merge/front/src/api/posts_wzy.js
@@ -36,11 +36,11 @@
* 发布新帖
* POST /posts
*/
-export async function createPost(payload) {
+export async function createPost(formData) {
const res = await fetch(`${BASE}/posts`, {
method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify(payload)
+ // 不设置Content-Type,让浏览器自动设置multipart/form-data
+ body: formData
})
if (!res.ok) {
const err = await res.json().catch(() => null)
@@ -53,11 +53,12 @@
* 修改帖子
* PUT /posts/{postId}
*/
-export async function updatePost(postId, payload) {
+export async function updatePost(postId, formData) {
const res = await fetch(`${BASE}/posts/${postId}`, {
method: 'PUT',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify(payload)
+ // 如果是FormData则不设置Content-Type,否则设置JSON
+ headers: formData instanceof FormData ? {} : { 'Content-Type': 'application/json' },
+ body: formData instanceof FormData ? formData : JSON.stringify(formData)
})
if (!res.ok) throw new Error(`updatePost(${postId}): ${res.status}`)
// 204 No Content