Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

上传的图片太大会直接panic #8

Closed
januwA opened this issue May 16, 2022 · 5 comments
Closed

上传的图片太大会直接panic #8

januwA opened this issue May 16, 2022 · 5 comments

Comments

@januwA
Copy link

januwA commented May 16, 2022

您好,我再上传一张21M的图片时直接panic,我测试小图片(小于4M)没有问题。

这是代码片段

                    log::info!("上传前");

                    let uploader: AutoUploader = upload_manager.auto_uploader();
                    let params = AutoUploaderObjectParams::builder()
                        .object_name(format!("{}/{}", content_type, filename))
                        .file_name(&filename)
                        .build();

                    let buffer = futures_util::io::Cursor::new(file_bytes);

                    log::info!("上传前2");
                    let res = uploader
                        .async_upload_reader(buffer, params)
                        .await
                        .map_err(ej)?;
                    log::info!("上传后");

这是报错信息

[2022-05-16T07:08:56Z INFO  server::controller::api::upload] 上传前
[2022-05-16T07:08:56Z INFO  server::controller::api::upload] 上传前2
thread 'async-std/runtime' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime', /root/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/tokio-1.17.0/src/runtime/context.rs:21:19
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'actix-rt|system:0|arbiter:0' panicked at 'task has failed', /root/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/async-task-4.2.0/src/task.rs:425:45
thread 'async-std/runtime' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime', /root/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/tokio-1.17.0/src/runtime/context.rs:21:19
thread 'async-std/runtime' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime', /root/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/tokio-1.17.0/src/runtime/context.rs:21:19

我在actix-web4中使用


开启RUST_BACKTRACE=1 的信息

github会出现 注释太长(最多65536个字符) 的错误信息,这里我上传文件
out.txt

@bachue
Copy link
Collaborator

bachue commented Jun 9, 2022

@januwA 确定下是否启用了 tokio1 feature

@januwA
Copy link
Author

januwA commented Jun 9, 2022

并没有

qiniu-sdk = { version = "0.1", features = [
  "utils",
  "etag",
  "credential",
  "upload",
  "upload-token",
  "http",
  "http-client",
  "reqwest",
  "apis",
  "objects",
  "async",
], optional = true }

@bachue
Copy link
Collaborator

bachue commented Jun 9, 2022

@januwA 哦 我知道了 你不应该用 reqwest 的,可以用 isahc 替换 reqwest,我估计你程序里没有 tokio 运行时,所以 reqwest 没法工作

@januwA
Copy link
Author

januwA commented Jun 10, 2022

我也不清楚,但我好像有tokio的运行时

[dependencies]
actix-web = "4"
tokio = { version = "1", features = ["full"] }

@bachue
Copy link
Collaborator

bachue commented Jun 10, 2022

@januwA tokio 运行时是要启动才能生效的,一般在 actix-web 里 用的是 actix-rt 这个运行时,当然你也可以用 tokio::task::spawn 启动 tokio 来执行 reqwest 库,只是可能这里不是太有必要。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants