-
Notifications
You must be signed in to change notification settings - Fork 435
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
Multiple files upload #157
Conversation
Codecov Report
@@ Coverage Diff @@
## master #157 +/- ##
============================================
+ Coverage 60.72% 61.31% +0.58%
- Complexity 145 147 +2
============================================
Files 29 29
Lines 802 809 +7
Branches 143 143
============================================
+ Hits 487 496 +9
+ Misses 229 228 -1
+ Partials 86 85 -1
Continue to review full report at Codecov.
|
@@ -140,6 +140,15 @@ class Request : Fuel.RequestConvertible { | |||
return this | |||
} | |||
|
|||
fun source(source: (Request, URL) -> File): Request { |
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.
Can we implement source
call sources
internally so we can save some duplications?
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.
Fixed. source
call sources
and add single file into List
.
@@ -131,7 +131,7 @@ class Request : Fuel.RequestConvertible { | |||
return this | |||
} | |||
|
|||
fun source(source: (Request, URL) -> File): Request { | |||
fun sources(source: (Request, URL) -> Array<File>): Request { |
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.
What do you think about return this as Iterable<File>
? This might make our API more flexible.
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.
Interesting.
write("--$boundary" + CRLF) | ||
write("Content-Disposition: form-data; name=\"" + it.first + "\"" + CRLF) | ||
write("Content-Type: text/plain" + CRLF) | ||
write("--$boundary$CRLF") |
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.
👏
} | ||
files.forEachIndexed { i, file -> | ||
val postFix = if (files.size == 1) "" else "${i + 1}" | ||
fileInputStream = FileInputStream(file) |
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.
You might consider move this to L43 so it gets closer to the place that we actually use.
Also as a protip, Kotlin use
function is very handy to work with anything implements closeable
interface.
FileInputStream(f).use {
//do something with inputstream
}
//automatically close the stream for us
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.
wow, that's cool. I will try it.
I have left some comments. Thanks so much for helping us implementing this feature 👏 |
@@ -131,7 +131,7 @@ class Request : Fuel.RequestConvertible { | |||
return this | |||
} | |||
|
|||
fun source(source: (Request, URL) -> File): Request { | |||
fun sources(source: (Request, URL) -> Collection<File>): Request { |
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.
Iterable
is better 🙏
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.
Oh, you review so fast. I will change it :).
|
||
write(CRLF) | ||
write("--$boundary$CRLF") | ||
write("Content-Disposition: form-data; name=\"" + request.name + "$postFix\"; filename=\"${file.name}\"") |
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.
Should we also make this as String interpolation?
This is awesome! Welcome @babedev for your first PR 💯 . 🚢 🇮🇹 from me. |
What's in this PR?
Implementation of multiple files upload as mentioned in #147 . I created new method call
sources
so we can pass multiple files intosourceCallback
.Example