私は、休憩サービスで次のリクエストパラメータを受け取るサービスコールを作成したいと考えています。このメソッドはファイルをイメージサーバーにアップロードします。ファイルをディスクに保存せずにBufferedImageをMultiPartファイルに変換するには?
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public ResponseEntity<String> uploadFile(
@RequestParam("file") MultipartFile file) {
次のサービスへの呼び出しが行われているコードです - あなたが見ることができるように私は、画像のURL
BufferedImage subImage= ImageIO.read(new URL(<some image url goes here>));
File outputFile = new File("C:\\" + "myimage" + ".jpg");
ImageIO.write(subImage, "jpg", outputFile);
MultiValueMap<String, Object> body = new LinkedMultiValueMap<String, Object>();
String url="http://serviceurl/upload";
body.add("file", outputFile);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<MultiValueMap<String, Object>>(body, headers);
restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
からBufferedImageオブジェクトで画像を読み込むと、ファイルが最初にされています作成してディスクに保存します。この手順を回避して、BufferedImageオブジェクトを使用するだけで(ファイルをローカルディスクに保存したくない)方法を教えてください。
以下の解決方法を試してみましたが、ディスクにファイルを保存せずにこれを達成できないようです。本当?
はMultipartFileは 'org.springframework.web.multipart.MultipartFile'からですか? – Jobin