fix(upload): 分片改 POST 并放宽 Nginx 反代,避免 PUT 大 body 断连
- 管理端分片请求改为 POST;后端同时保留 PUT - /api/ 增加 proxy_request_buffering off;CORS Allow-Headers 略扩展 Made-with: Cursor
This commit is contained in:
@@ -104,7 +104,7 @@ export const getMultipartUploadStatus = (siteId, uploadId) =>
|
||||
request.get(`/admin/sites/${siteId}/assets/multipart/${uploadId}/status`, { timeout: 60000 })
|
||||
|
||||
export const putMultipartChunk = (siteId, uploadId, chunkIndex, blob) =>
|
||||
request.put(`/admin/sites/${siteId}/assets/multipart/${uploadId}/chunk/${chunkIndex}`, blob, {
|
||||
request.post(`/admin/sites/${siteId}/assets/multipart/${uploadId}/chunk/${chunkIndex}`, blob, {
|
||||
headers: { 'Content-Type': 'application/octet-stream' },
|
||||
timeout: 180000
|
||||
})
|
||||
|
||||
@@ -44,6 +44,7 @@ server {
|
||||
proxy_send_timeout 86400s;
|
||||
proxy_read_timeout 86400s;
|
||||
proxy_buffering off;
|
||||
proxy_request_buffering off;
|
||||
}
|
||||
|
||||
location /admin/ {
|
||||
|
||||
@@ -76,6 +76,7 @@ server {
|
||||
proxy_send_timeout 86400s;
|
||||
proxy_read_timeout 86400s;
|
||||
proxy_buffering off;
|
||||
proxy_request_buffering off;
|
||||
}
|
||||
|
||||
# 尾斜杠形式:proxy_pass 带 / 会去掉 /admin 前缀,上游收到 /assets/…、/index.html 等
|
||||
|
||||
@@ -82,6 +82,7 @@ server {
|
||||
proxy_send_timeout 86400s;
|
||||
proxy_read_timeout 86400s;
|
||||
proxy_buffering off;
|
||||
proxy_request_buffering off;
|
||||
}
|
||||
|
||||
location /admin/ {
|
||||
|
||||
@@ -215,7 +215,7 @@ func MultipartUploadStatus(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// PutMultipartChunk 上传单个分片(二进制 body,长度须与分片大小一致)
|
||||
// PutMultipartChunk 上传单个分片(二进制 body,长度须与分片大小一致)。路由同时注册 POST 与 PUT,建议客户端用 POST。
|
||||
func PutMultipartChunk(c *gin.Context) {
|
||||
siteID := c.Param("site_id")
|
||||
uploadID := c.Param("upload_id")
|
||||
|
||||
@@ -99,7 +99,7 @@ func main() {
|
||||
c.Header("Access-Control-Allow-Origin", "*")
|
||||
}
|
||||
c.Header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
|
||||
c.Header("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
||||
c.Header("Access-Control-Allow-Headers", "Content-Type, Authorization, Accept, Origin, X-Requested-With")
|
||||
if c.Request.Method == "OPTIONS" {
|
||||
c.AbortWithStatus(http.StatusNoContent)
|
||||
return
|
||||
@@ -174,6 +174,8 @@ func main() {
|
||||
admin.POST("/sites/:site_id/assets", handlers.RequirePermission(models.PermModuleUpload), handlers.UploadSiteAsset)
|
||||
admin.POST("/sites/:site_id/assets/init-multipart", handlers.RequirePermission(models.PermModuleUpload), handlers.InitMultipartUpload)
|
||||
admin.GET("/sites/:site_id/assets/multipart/:upload_id/status", handlers.RequirePermission(models.PermModuleUpload), handlers.MultipartUploadStatus)
|
||||
// 分片用 POST:部分反向代理对 PUT + 大 body 会断连,浏览器表现为 Network Error
|
||||
admin.POST("/sites/:site_id/assets/multipart/:upload_id/chunk/:chunk_index", handlers.RequirePermission(models.PermModuleUpload), handlers.PutMultipartChunk)
|
||||
admin.PUT("/sites/:site_id/assets/multipart/:upload_id/chunk/:chunk_index", handlers.RequirePermission(models.PermModuleUpload), handlers.PutMultipartChunk)
|
||||
admin.POST("/sites/:site_id/assets/multipart/:upload_id/complete", handlers.RequirePermission(models.PermModuleUpload), handlers.CompleteMultipartUpload)
|
||||
admin.DELETE("/sites/:site_id/assets/multipart/:upload_id", handlers.RequirePermission(models.PermModuleUpload), handlers.AbortMultipartUpload)
|
||||
|
||||
Reference in New Issue
Block a user