-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add support for download
function in web
#2230
base: main
Are you sure you want to change the base?
Changes from 8 commits
c429be1
7147d04
6e5a96b
4dec223
3853fc9
7cf567f
0b1fbe6
77c63b8
7bc44a1
cf1c52d
1bbc7f9
9db2305
5917273
d029294
9f1f36e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,8 @@ class BrowserHttpClientAdapter implements HttpClientAdapter { | |
xhrs.add(xhr); | ||
xhr | ||
..open(options.method, '${options.uri}') | ||
..responseType = 'arraybuffer'; | ||
..responseType = | ||
options.responseType == ResponseType.blobUrl ? 'blob' : 'arraybuffer'; | ||
|
||
final withCredentialsOption = options.extra['withCredentials']; | ||
if (withCredentialsOption != null) { | ||
|
@@ -65,18 +66,35 @@ class BrowserHttpClientAdapter implements HttpClientAdapter { | |
final completer = Completer<ResponseBody>(); | ||
|
||
xhr.onLoad.first.then((_) { | ||
final Uint8List body = (xhr.response as ByteBuffer).asUint8List(); | ||
completer.complete( | ||
ResponseBody.fromBytes( | ||
body, | ||
xhr.status!, | ||
headers: xhr.responseHeaders.map((k, v) => MapEntry(k, v.split(','))), | ||
statusMessage: xhr.statusText, | ||
isRedirect: xhr.status == 302 || | ||
xhr.status == 301 || | ||
options.uri.toString() != xhr.responseUrl, | ||
), | ||
); | ||
if (options.responseType == ResponseType.blobUrl) { | ||
completer.complete( | ||
ResponseBody.fromString( | ||
Url.createObjectUrl(xhr.response), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you reuse other fields by constructing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
xhr.status!, | ||
headers: | ||
xhr.responseHeaders.map((k, v) => MapEntry(k, v.split(','))), | ||
statusMessage: xhr.statusText, | ||
isRedirect: xhr.status == 302 || | ||
xhr.status == 301 || | ||
options.uri.toString() != xhr.responseUrl, | ||
), | ||
); | ||
} else { | ||
final Uint8List body = (xhr.response as ByteBuffer).asUint8List(); | ||
completer.complete( | ||
ResponseBody.fromBytes( | ||
body, | ||
xhr.status!, | ||
headers: xhr.responseHeaders.map( | ||
(k, v) => MapEntry(k, v.split(',')), | ||
), | ||
statusMessage: xhr.statusText, | ||
isRedirect: xhr.status == 302 || | ||
xhr.status == 301 || | ||
options.uri.toString() != xhr.responseUrl, | ||
), | ||
); | ||
} | ||
}); | ||
|
||
Timer? connectTimeoutTimer; | ||
|
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 description seems to lack explanation.
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.
I made changes to the description