-
Notifications
You must be signed in to change notification settings - Fork 38
feat: send files directly from bytes #260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
EdJoPaTo
wants to merge
21
commits into
master
Choose a base branch
from
edjopato/filehandling
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a5bd40f
feat: send files directly from bytes
EdJoPaTo bc10f7c
refactor: less error-prone new_params without InputFile
EdJoPaTo d56bf46
refactor: move internal method to the end of the impl
EdJoPaTo 1550453
Merge branch 'master' into edjopato/filehandling
EdJoPaTo 44bcac6
Merge branch 'master' into edjopato/filehandling
EdJoPaTo 3feeaa6
fix(client-ureq): add back mime_guess
EdJoPaTo cb87c98
Merge remote-tracking branch 'origin/master' into edjopato/filehandling
EdJoPaTo 64625c3
test(client-ureq): use include_bytes for more realistic dummyfile
EdJoPaTo c94e76c
fix(macros): InputFile no longer has impl From
EdJoPaTo 7ccfa89
Merge branch 'master' into edjopato/filehandling
EdJoPaTo a4e50b7
Merge remote-tracking branch 'origin/master' into edjopato/filehandling
EdJoPaTo c5629e0
refactor: use simpler io::Error::other
EdJoPaTo 1ff7f49
perf(files): keep PathBuf variant as its optimized by multistream
EdJoPaTo a168c9b
docs(readme): remove relatively clear upload docs
EdJoPaTo 02a1936
Merge remote-tracking branch 'origin/master' into edjopato/filehandling
EdJoPaTo dc2b8d7
Merge remote-tracking branch 'origin/master' into edjopato/filehandling
EdJoPaTo ac2aaf2
refactor: generalize methods with file uploads
EdJoPaTo 414c573
docs(traits): add docs for the manually implemented methods
EdJoPaTo 80f83ec
feat(files): move instead of clone
EdJoPaTo e616f3b
fixup! feat(files): move instead of clone
EdJoPaTo 6676ee3
perf: parse directly into map
EdJoPaTo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| use frankenstein::api_params::SendPhotoParams; | ||
| use frankenstein::client_ureq::Bot; | ||
| use frankenstein::input_file::InputFile; | ||
| use frankenstein::TelegramApi; | ||
|
|
||
| fn main() { | ||
| let token = std::env::var("BOT_TOKEN").expect("Should have BOT_TOKEN as environment variable"); | ||
| let chat_id = std::env::var("TARGET_CHAT") | ||
| .expect("Should have TARGET_CHAT as environment variable") | ||
| .parse::<i64>() | ||
| .expect("TARGET_CHAT should be i64"); | ||
|
|
||
| let bot = Bot::new(&token); | ||
|
|
||
| let file = InputFile::read_std("./frankenstein_logo.png").expect("Should be able to read file"); | ||
| println!("File size: {}", file.bytes.len()); | ||
|
|
||
| let params = SendPhotoParams::builder() | ||
| .chat_id(chat_id) | ||
| .photo(file) | ||
| .build(); | ||
| match bot.send_photo(¶ms) { | ||
| Ok(response) => { | ||
| println!("Photo was uploaded successfully"); | ||
| dbg!(response); | ||
| } | ||
| Err(error) => { | ||
| eprintln!("Failed to upload photo: {error:?}"); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This
bytes.clone()is kinda horrible. Even with the rest of this approach being refactored into references, reqwest still requires a clone here.And for 1.5 GB file data, this is definitely a lot.
The best we could do would require the ownership and pass it over to reqwest so it's never cloned by frankenstein and only explicitly by the user of frankenstein when needed.
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.
ureq would work with references while reqwest doesn't. But frankenstein requires either both with references or none.