qiniu / rust-sdk

Generic Qiniu Resource Storage SDK
MIT License
26 stars 7 forks source link

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

Closed januwA closed 2 years ago

januwA commented 2 years ago

您好,我再上传一张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 commented 2 years ago

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

januwA commented 2 years ago

并没有

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

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

januwA commented 2 years ago

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

[dependencies]
actix-web = "4"
tokio = { version = "1", features = ["full"] }
bachue commented 2 years ago

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