Repository: seanmonstar/reqwest (language: rust)

Issue:
Easy build multipart from &[u8]
I want to post a multipart form from `&[u8]` which is read from a `std::fs::File`. The multipart form needs to be sended without encoding `Transfer-Encoding: chunked`.
The easy way should be following:

```rust
fn to_post(buf: &[u8]) {
    let c: Vec<u8> = buf.iter().map(|a| a.clone()).collect();
    let part = reqwest::multipart::Part::new(Body::from(buf)).file_name("abc");
    let form = reqwest::multipart::Form::new().part("file", part);

    // request
}
```

But, `reqwest::multipart::Part::new` is not public.
So I must use local `reqwest` and change `reqwest::multipart::Part::new` to be public.
@seanmonstar can you let it to be public.


Discussion / hints:
Could you use [`Part::reader_with_length`](https://docs.rs/reqwest/0.8.0/reqwest/multipart/struct.Part.html#method.reader_with_length) to do it?

```rust
fn to_post(buf: &[u8]) {
    let c = buf.to_vec();
    let part = reqwest::multipart::Part::reader_with_length(c, buf.len())
        .file_name("abc");
    let form = reqwest::multipart::Form::new().part("file", part);

    // request
}
```
`Part::reader_with_length` does not work.
`io::Read` is not implemented for `Vec<u8>`

```rust
error[E0277]: the trait bound `std::vec::Vec<u8>: std::io::Read` is not satisfied
  --> src/main.rs:18:16
   |
18 |     let part = reqwest::multipart::Part::reader_with_length(c, buf.len() as u64)
   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::io::Read` is not implemented for `std::vec::Vec<u8>`
   |
   = note: required by `reqwest::multipart::Part::reader_with_length`
```
Oh right, a Vec isn't Read. You could wrap it in a `std::io:: Cursor`.

Still, it might be nice if we added a `Part::bytes(buf)` constructor that's just like text, but not utf8.
@seanmonstar Thanks.
`std::io::Cursor` is working.
Adding a `Part::bytes` will be better 👍.

Fix patch:
diff --git a/src/multipart.rs b/src/multipart.rs
index 6ffcc2971..6e445c678 100644
--- a/src/multipart.rs
+++ b/src/multipart.rs
@@ -148,6 +148,17 @@ impl Part {
         Part::new(body)
     }
 
+    /// Makes a new parameter from arbitrary bytes
+    pub fn bytes<T>(value: T) -> Part
+    where T: Into<Cow<'static, [u8]>>
+    {
+        let body = match value.into() {
+            Cow::Borrowed(slice) => Body::from(slice),
+            Cow::Owned(vec) => Body::from(vec),
+        };
+        Part::new(body)
+    }
+
     /// Adds a generic reader.
     ///
     /// Does not set filename or mime.


Test patch: