注意點:
- zuul 中默認(rèn)的文件上傳大小為 1M
- nginx 中默認(rèn)的文件上傳大小為 1M
相關(guān)問題
場景1:
如果只需要上傳1M及以下的文件, 當(dāng)我們在發(fā)送上傳圖片的請求是會出現(xiàn)以下異常。

解決:
在
gateway.yml對該service的route進行處理
zuul:
routes:
app-demo:
path: /app-demo/**
url: http://app-demo:8080
##改為
zuul:
routes:
app-demo:
path: /app-demo/**
serviceId: appDemoUploadImage
appDemoUploadImage:
ribbon:
NIWSServerListClassName: com.netflix.loadbalancer.ConfigurationBasedServerList
listOfServers: http://app-demo:8080
場景2:
如果上傳圖片大于 1M,那么需要
- 在 nginx 中配置
client_max_body_size xxMB - 在當(dāng)前service項目下的
bootstrap.yml中添加配置信息(一定要在bootstrap.yml中設(shè)置)
spring:
servlet:
multipart:
max-file-size: xxMB
max-request-size: xxMB
- 假如我們的上傳接口為
http://localhost:8080/api/upload,那么我們在上傳的時候需要加上/zuul,即curl -F "photo=@pic.jpg" http://localhost:8080/zuul/api/upload才能正確的上傳成功
場景3:
當(dāng)上傳圖片過大時,會出現(xiàn) timeout 的異常。
解決:在gateway.yml 中添加超時時長設(shè)置
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 10000 // 以秒為單位