rocket_upload 0.1.0

Deal MultiPart Form Data in Rust Rocket web frame, easily upload files to server.
Documentation
  • Coverage
  • 0%
    0 out of 12 items documented0 out of 5 items with examples
  • Size
  • Source code size: 59.4 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 773.95 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 55s Average build duration of successful builds.
  • all releases: 55s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • formoon/rocket-upload
    5 0 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • formoon

Deal MultiPart Form Data in Rust Rocket web frame, easily upload files to server.

All code is in lib.rs. main.rs is a good example to see how it work.

Fist:

use rocket_upload::MultipartDatas;

Then in your handler:

#[post("/upload/<userid>", data = "<data>")]
fn upload(userid: String, content_type: &ContentType, data: MultipartDatas) -> Html<String>
{
  // to get a param from client
  let mut result=format!("UserID:{}<br>",userid);
  // content_type not used here, just for more informations
  result = format!("{}{:?}<br>",result,content_type);
  // aquire all Form field data
  for t in data.texts {
    result = format!("{}FieldName:{} --- FieldValue:{}<br>",result,t.key,t.value);
  }
  // aquire all files upload 
  for f in data.files {
    result = format!("{}FieldName:{} --- FileName:{} --- StoragePath:{}<br>",
      result,f.name,f.filename,f.path);
    f.persist(Path::new("upload"));
  }
  Html(format!("<html><head></head><body>upload coming...<br>{}</body></html>",result))
}

The project references the code of Magic Len's https://crates.io/crates/rocket-multipart-form-data