简体   繁体   English

如何将图像/文件的 base64 字符串转换为 FilePart

[英]How to convert base64 string of image / file to FilePart

On my frontend application, images and files are converted to base64 string before being sent to the backend.在我的前端应用程序中,图像和文件在发送到后端之前被转换为 base64 字符串。

I am trying to upload those image and files to gofile.io using a custom webClient with FilePart as a @RequestPart我正在尝试使用带有 FilePart 作为 @RequestPart 的自定义 webClient 将这些图像和文件上传到 gofile.io

@RequestMapping(value = "/uploadFile", method = RequestMethod.POST,
          consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
  Mono<UploadResumeResponse> uploadResume(@RequestPart("file") FilePart file);

I want to convert my base 64 string provided by frontend to a FilePart and then use the client to upload the file.我想将前端提供的 base 64 字符串转换为 FilePart,然后使用客户端上传文件。 Any idea how to do that?知道怎么做吗?

Thanks in advance!提前致谢!

If you have it as base64 then upload it as normal post with body then on backend create DTO class then decode it to bytes and upload it.如果您将其作为 base64 上传,则将其作为带有正文的普通帖子上传,然后在后端创建 DTO 类,然后将其解码为字节并上传。

@Data
    public class UploadDto{
        String file;
    }
    Mono<String> uploadResume(@RequestBody UploadDto request){
        byte[] imgBytes = Base64.getDecoder().decode(request.getFile());
        
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM