我有一个带有Spring Boot的API支架,并通过它上传了一个视频,问题是,当我在本地环境中运行它时,它可以完美地播放长视频,并实际上将它们上传到我在gcloud中的存储中,但是当我将此视频上传到生产中会引发错误413实体太大。
任何想法,为什么它在本地而不是在生产中工作
这是控制器:
@RequestMapping(value = "/{videoId}/upload", method = RequestMethod.POST )
public ResponseEntity<Object> uploadTest(@PathVariable Long videoId, @RequestParam("file") MultipartFile file) {
try {
return ResponseEntity.ok(uploadVideo(videoId, file));
} catch (Exception e) {
return processException(e);
}
}
此函数从控制器调用:
public String uploadVideo(MultipartFile fileStream, final String folder, final String bucketName) throws IOException, ServletException {
InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream("project.json");
storage = getInstance(resourceAsStream);
String blobName = fileStream.getName();
BlobId blobId = BlobId.of(bucketName, blobName);
byte[] content = fileStream.getBytes();
DateTimeFormatter dtf = DateTimeFormat.forPattern("-YYYY-MM-dd-HHmmssSSS");
DateTime dt = DateTime.now(DateTimeZone.UTC);
String dtString = dt.toString(dtf);
String extension = fileStream.getOriginalFilename().substring(fileStream.getOriginalFilename().lastIndexOf(".") + 1);
final String fileName = fileStream.getName() + dtString + "." + extension;
BlobInfo blobInfo = BlobInfo.newBuilder(bucketName, folder + "/" + fileName)
.setAcl(new ArrayList<>(Arrays.asList(Acl.of(User.ofAllUsers(), Role.READER))))
.build();
try (WriteChannel writer = storage.writer(blobInfo)) {
try {
writer.write(ByteBuffer.wrap(content, 0, content.length));
return "https://storage.googleapis.com/" + bucketName + "/" + folder + "/" + fileName;
} catch (Exception ex) {
System.out.println(ex.toString());
throw new BadRequestException("Error uploading");
}
}
}
非常感谢,为您提供帮助
App Engine(标准?)将请求大小限制为32MB(link)。
虽然这是可以理解的,但我认为假定开发服务器是生产服务的代理不是一个好习惯。
我建议您将文件直接上传到Cloud Storage,并考虑使用notifications例如排队对象的元数据,最终触发您的App Engine处理程序。