我正在使用Spring Boot,并且可以发送小于1MB的图像,但是当我发出具有大于1MB的大图像的发布请求时,出现此错误:
Maximum upload size exceeded; nested exception is java.lang.IllegalStateException:org.apache.tomcat.util.
http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.
Run Code Online (Sandbox Code Playgroud)
我到处寻找很多地方来尝试找到此错误的答案。我查看了所有这些问题,并尝试实施它们的建议,但无济于事:Spring上传文件大小限制, 我试图设置maxFileSize,但不兑现,org.apache.tomcat.util.http.fileupload.FileUploadBase $ 春季启动时FileSizeLimitExceededException和MultipartFile的最大限制
我正在使用Spring 2.0.3版本,这是我的帖子映射:
@PostMapping("/post")
public ResponseEntity<String> handleFileUpload(@RequestParam("file") MultipartFile file) {
String message = "";
try {
storageService.store(file);
files.add(file.getOriginalFilename());
message = "You successfully uploaded " + file.getOriginalFilename() + "!";
return ResponseEntity.status(HttpStatus.OK).body(message);
} catch (Exception e) {
message = "FAIL to upload " + file.getOriginalFilename() + "!";
return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body(message);
} …Run Code Online (Sandbox Code Playgroud) 学习决赛,我遇到了这个问题.他们询问以下代码执行printf的次数:
#include "csapp.h"
void doit() {
Fork();
Fork();
printf("hello\n");
return;
}
int main()
{
doit();
printf("hello\n");
exit(0);
}
Run Code Online (Sandbox Code Playgroud)
解决方案说它printf执行了8次,但我无法弄清楚原因.我一直试图绘制代码中发生的事情的图片,但我的图片看起来好像只执行了4次.
我设置了一个基本的 Python Flask API,它没有将 ID 作为 GET 请求的参数。在 get 请求逻辑中,我正在对另一个资源执行 get 请求,以检索与传入的 ID 关联的图像:
image = requests.get(url = image_url)
image = Image.open(BytesIO(image.content))
print(image.format)
Run Code Online (Sandbox Code Playgroud)
它返回的图像格式为JPEG.
我想将其添加为 API 响应的一部分。这是我的 GET 端点的定义:
@app.route('/getmsg/', methods=['GET'])
def respond():
Run Code Online (Sandbox Code Playgroud)
这就是我尝试返回从其他资源获得的图像的方式:
return {"image": send_file(image, mimetype='image/jpeg'), "data": jsonify(return_list)}
Run Code Online (Sandbox Code Playgroud)
我已经尝试遵循这个 stackoverflow 问题:How to return images inflask response?
这就是我如何到达现在的位置。我通过此端点发出 get 请求:http://localhost:5000/getmsg/?id=7187167507933759112。
我也尝试过只返回图像,如下所示:
return send_file(image, mimetype='image/jpeg')
Run Code Online (Sandbox Code Playgroud)
但它给了我同样的错误。
除了返回图像之外,一切正常。
我希望能够在 get 请求的响应中看到图像,但现在它给出 500 内部服务器错误。
这是我在终端中得到的响应:
TypeError: <Response 693 bytes [200 OK]> is not JSON serializable
Run Code Online (Sandbox Code Playgroud)
任何有关我做错了什么的指导将不胜感激。谢谢。
这是我的TA帮助我获得的代码,但后来我完全忘记了它是如何工作的,因为我似乎无法得到正确的答案,而面试评分是明天.如果有人可以提供帮助请.谢谢
* bitCount - returns count of number of 1's in word
* Examples: bitCount(5) = 2, bitCount(7) = 3
* Legal ops: ! ~ & ^ | + << >>
* Max ops: 40
* Rating: 4
*/
int bitCount(int x) {
int m4 = 0x1 | (0x1<<8) | (0x1<<16) | (0x1<<24);
int m1 = 0xFF;
int s4 = (x&m4) + ((x>>1)&m4) + ((x>>2)&m4) + ((x>>3)&m4) + ((x>>4)&m4) + ((x>>5)&m4) + ((x>>6)&m4) + ((x>>7)&m4);
int s1 = (s4&m1) + …Run Code Online (Sandbox Code Playgroud) 我使用以下方法生成600长度样本:
x <- rnorm(600, mean = 30, sd = 10)
Run Code Online (Sandbox Code Playgroud)
然后使用以下方法制作另一个600长度列表
y = ((x-30)/10)
Run Code Online (Sandbox Code Playgroud)
并且我的计划是使用if语句来测试y是否大于1.96并且如果-y小于1.96并且如果发生这种情况则将变量a增加1并且如果这不发生则将变量b增加1.
我试过以下的事情:
a = 0
b = 0
ifelse(y > 1.96, inc(a) <- 1, inc(b) <- 1)
ifelse(-y < -1.96, inc(a) <- 1, inc(b) <- 1)
Run Code Online (Sandbox Code Playgroud)
inc(a)< - 1中的错误:找不到函数"inc < - "inc(b)中的错误< - 1:找不到函数"inc < - "
ifelse(y > 1.96, '+'(a) <- 1, '+'(b) <- 1)
ifelse(-y < -1.96, '+'(a) <- 1, '+'(b) <- 1)
Run Code Online (Sandbox Code Playgroud)
+ a < - 1中的错误:找不到函数"+ …
MockMultipartFile我正在尝试在 Egads 的现有源代码中使用,但我不断收到此错误:package org.springframework.mock.web does not exist
这是更新后的 pom 文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yahoo.egads</groupId>
<artifactId>egads</artifactId>
<name>EGADS Anomaly Detection System</name>
<description>EGADS system, consumes time series and outputs anomalies.</description>
<version>0.4.0</version>
<organization>
<name>Yahoo Inc.</name>
<url>https://www.yahoo.com/</url>
</organization>
<inceptionYear>2015</inceptionYear>
<developers>
<developer>
<organization>Yahoo Inc.</organization>
<organizationUrl>https://www.yahoo.com/</organizationUrl>
</developer>
</developers>
<licenses>
<license>
<name>GPL V3</name>
<url>https://www.gnu.org/licenses/gpl-3.0.en.html</url>
<distribution>repo</distribution>
</license>
</licenses>
<packaging>jar</packaging>
<issueManagement>
<system>Github</system>
<url>https://github.com/yahoo/egads/issues</url>
</issueManagement>
<ciManagement>
<system>Travis</system>
<url>https://travis-ci.org/yahoo/egads</url>
</ciManagement>
<distributionManagement>
<repository>
<id>bintray-yahoo-egads</id>
<name>yahoo-egads</name>
<url>https://api.bintray.com/maven/yahoo/maven/egads;publish=1</url>
</repository>
</distributionManagement>
<properties>
<spring-boot.version>2.0.3.RELEASE</spring-boot.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<repositories>
<repository> …Run Code Online (Sandbox Code Playgroud)