Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of garbled Chinese file name when uploading files by Zuul

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "how to solve the problem of Chinese file name garbled when uploading files by Zuul". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Problem description

There is another oss service for uploading files in the project. The file is uploaded successfully by calling the service directly. If you upload a file with a Chinese name through the gateway zuul service, the file name will be garbled, resulting in the upload failure. If you upload a file with an English name, there will be no problem. It is suspected that the gateway zuul encodes the Chinese language.

The process of solving a problem

After the emergence of this problem, my personal solution is as follows:

The first reaction is to look at the document, document address: http://cloud.spring.io/spring-cloud-static/Dalston.SR1/#_uploading_files_through_zuul

I glanced at the document and thought that no solution had been given (in fact, it had been given, but the document was not well understood). Frenzied with the source code, still did not find a solution.

Google search, found this Issue, https://github.com/spring-cloud/spring-cloud-netflix/issues/1385

The solution given by the great god is to use zuul servlet to upload files instead of the default spring mvc. To use zuul servlet, you need to request uri, preceded by "/ zuul".

Solution

First list the configuration of my zuul service:

Server.port: 5000zuul: routes: oss-api: path: / oss/** serviceId: oss-service

The API for uploading files from oss service is as follows:

@ RestController@RequestMapping ("/ file") public class FileUploadController {@ PostMapping ("/ upload") public RespDTO handleFileUpload (@ RequestParam ("file") MultipartFile file) {/ / upload code omit return RespDTO.onSuc (upLoadResult);}

Then, after passing through the gateway, the url address of the file to be uploaded is as follows:

Localhost:5000/oss/file/upload

At this time, if the Chinese file name appears, the file name of the uploaded file will fail. According to the above method, add "/ zuul" to the uri directly, and the request address is as follows:

Localhost:5000/zuul/oss/file/upload

Test, and sure enough, upload the Chinese name of the file garbled problem solved.

This is the end of the content of "how to solve the garbled Chinese file name when uploading files by Zuul". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report