spring boot + spring cloud config + hystrix + spring gateway +zuul + nginx 上傳圖片的一些坑

注意點:

  • zuul 中默認(rèn)的文件上傳大小為 1M
  • nginx 中默認(rèn)的文件上傳大小為 1M

相關(guān)問題

場景1:

如果只需要上傳1M及以下的文件, 當(dāng)我們在發(fā)送上傳圖片的請求是會出現(xiàn)以下異常。


解決:
gateway.yml對該serviceroute進行處理

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 // 以秒為單位
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容