1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-24 07:53:00 +01:00

add README example/multipart

This commit is contained in:
ami44 2017-12-30 16:09:39 +01:00
parent d7d9e8c0e9
commit a1a77600c6
3 changed files with 32 additions and 3 deletions

View File

@ -10,5 +10,5 @@ path = "src/main.rs"
[dependencies] [dependencies]
env_logger = "*" env_logger = "*"
futures = "0.1" futures = "0.1"
actix = "^0.3.4" actix = "^0.3.5"
actix-web = { git = "https://github.com/actix/actix-web.git" } actix-web = { git = "https://github.com/actix/actix-web", features=["signal"] }

View File

@ -0,0 +1,24 @@
# multipart
Multipart's `Getting Started` guide for Actix web
## Usage
### server
```bash
cd actix-web/examples/multipart
cargo run (or ``cargo watch -x run``)
# Started http server: 127.0.0.1:8080
```
### client
- ``pip install aiohttp``
- ``python client.py``
- you must see in server console multipart fields
if ubuntu :
- ``pip3 install aiohttp``
- ``python3 client.py``

View File

@ -9,6 +9,8 @@ use actix_web::*;
use futures::{Future, Stream}; use futures::{Future, Stream};
use futures::future::{result, Either}; use futures::future::{result, Either};
use actix::Arbiter;
use actix::actors::signal::{ProcessSignals, Subscribe};
fn index(mut req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> fn index(mut req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>>
{ {
@ -46,13 +48,16 @@ fn main() {
let _ = env_logger::init(); let _ = env_logger::init();
let sys = actix::System::new("multipart-example"); let sys = actix::System::new("multipart-example");
HttpServer::new( let addr = HttpServer::new(
|| Application::new() || Application::new()
.middleware(middleware::Logger::default()) // <- logger .middleware(middleware::Logger::default()) // <- logger
.resource("/multipart", |r| r.method(Method::POST).a(index))) .resource("/multipart", |r| r.method(Method::POST).a(index)))
.bind("127.0.0.1:8080").unwrap() .bind("127.0.0.1:8080").unwrap()
.start(); .start();
let signals = Arbiter::system_registry().get::<ProcessSignals>();
signals.send(Subscribe(addr.subscriber()));
println!("Starting http server: 127.0.0.1:8080"); println!("Starting http server: 127.0.0.1:8080");
let _ = sys.run(); let _ = sys.run();
} }