通过发布将BLOB发送到Java后端

问题描述 投票:0回答:1

我在Angular项目中使用recordRTC录制了一个视频,现在我需要通过Post将该视频发送到我的后端Java应用程序。

这是我的邮政编码:

mediaRecorder.onstop = (ev) = > {
    let blob = new Blob(chunks, {
        'type': 'video/mp4;'
    });
    chunks = [];
    let videoURL = window.URL.createObjectURL(blob);
    vidSave.src = videoURL;
    var file = new File([blob], 'video.mp4', {
        type: 'video/mp4'
    });
}

[您可以看到我已准备好发送Blob,现在如何通过邮寄方式发送它?格式是什么?

@PostMapping("/recieveAndParseVideo")
public void recieveAndParseVideo( //WHATS the parameter here? form-input? string? blob?) {
    // HOW I RECIEVE THE BLOB HERE?
}
java angular
1个回答
0
投票

发送文件的最佳方式是使用formData,因此在Angular中使用

formData = new FormData();
this.formData.append('file', blob);

postMyBlob(formData: any) {
    return this.http.post(`${AppUtils.REST_API_SERVER}/upload-file`, formData);
  }

然后在你的背上

   @RequestMapping(value = "/upload-file", method = RequestMethod.POST)
   public ResponseEntity<Void> getUploadFile(@RequestParam("file") MultipartFile file) {
            LOGGER.debug(String.valueOf(file));
    }
© www.soinside.com 2019 - 2024. All rights reserved.