-
-
Couldn't load subscription status.
- Fork 4
Update attachment start API #3
Conversation
- API is now more strict about requiring an integer for `contentLength`. Numeric strings are no longer accepted. - `width` and `height` are now available (albeit optional) fields. Including these is preferred. I included an implementation for this, although I am amateurish at rust so my way of getting around borrowing `path` probably is incorrect. Would love to know what's actually idiomatic here. Tested this works as expected with no changes required for `examples/post.rs`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh, imagesize is a really smol library. Good find; I would have otherwise recommended making that an optional dependency but I think there's no need.
src/attachment.rs
Outdated
| .to_owned(); | ||
|
|
||
| let file = File::open(path).await?; | ||
| let file = File::open(path.clone()).await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usual way I handle this is, at the top of the function, writing something like:
let path = path.as_ref();path becomes a &Path, which also impls AsRef<Path>, so it can be passed to both functions without a clone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sick thank you! constantly learning new things
| let file = File::open(path).await?; | ||
| let file = File::open(path.clone()).await?; | ||
| let content_length = file.metadata().await?.len(); | ||
| let stream = Body::wrap_stream(FramedRead::new(file, BytesCodec::new())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative implementation could use imagesize::reader_size with &mut file here, before moving the file into this Body.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tried this at first but couldn't really finagle it into working. probably just something i Don't Know but didn't really want to keep fucking with it
made it optional anyway so that i can learn how to do that (happy to undo that though) |
|
Can you test building with |
|
all good, still builds |
|
Thanks! If I don't get terribly distracted I'll get a release out. |
|
Tested and working for me as well |
contentLength. Numeric strings are no longer accepted.widthandheightare now available (albeit optional) fields. Including these is preferred. I included an implementation for this, although I am amateurish at rust so my way of getting around borrowingpathafter moving (clones!) is probably incorrect. Would love to know what's actually idiomatic here.Tested this works as expected with no changes required for
examples/post.rs.