Skip to content

Commit edd3277

Browse files
committed
added progressCallback to file upload
for parse-community#366
1 parent 35b562f commit edd3277

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

lib/src/objects/parse_file.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,16 @@ class ParseFile extends ParseFileBase {
5050
final Directory tempPath = await getTemporaryDirectory();
5151
file = File('${tempPath.path}/$name');
5252
await file.create();
53-
final Response<List<int>> response = await _client.get<List<int>>(url, options: Options(responseType: ResponseType.bytes));
53+
final Response<List<int>> response = await _client.get<List<int>>(url,
54+
options: Options(responseType: ResponseType.bytes));
5455
await file.writeAsBytes(response.data);
5556

5657
return this;
5758
}
5859

5960
/// Uploads a file to Parse Server
6061
@override
61-
Future<ParseResponse> upload() async {
62+
Future<ParseResponse> upload({ProgressCallback progressCallback}) async {
6263
if (saved) {
6364
//Creates a Fake Response to return the correct result
6465
final Map<String, String> response = <String, String>{
@@ -80,8 +81,12 @@ class ParseFile extends ParseFileBase {
8081
try {
8182
final String uri = _client.data.serverUrl + '$_path';
8283
final List<int> body = await file.readAsBytes();
83-
final Response<String> response = await _client.post<String>(uri,
84-
options: Options(headers: headers), data: body);
84+
final Response<String> response = await _client.post<String>(
85+
uri,
86+
options: Options(headers: headers),
87+
data: body,
88+
onSendProgress: progressCallback,
89+
);
8590
if (response.statusCode == 201) {
8691
final Map<String, dynamic> map = json.decode(response.data);
8792
url = map['url'].toString();

lib/src/objects/parse_file_base.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ abstract class ParseFileBase extends ParseObject {
4141
}
4242

4343
/// Uploads a file to Parse Server
44-
Future<ParseResponse> upload();
44+
Future<ParseResponse> upload({ProgressCallback progressCallback});
4545

4646
Future<ParseFileBase> download();
4747
}

lib/src/objects/parse_file_web.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ParseWebFile extends ParseFileBase {
3131
}
3232

3333
@override
34-
Future<ParseResponse> upload() async {
34+
Future<ParseResponse> upload({ProgressCallback progressCallback}) async {
3535
if (saved) {
3636
//Creates a Fake Response to return the correct result
3737
final Map<String, String> response = <String, String>{
@@ -53,8 +53,12 @@ class ParseWebFile extends ParseFileBase {
5353
};
5454
try {
5555
final String uri = _client.data.serverUrl + '$_path';
56-
final Response<String> response = await _client.post<String>(uri,
57-
options: Options(headers: headers), data: file);
56+
final Response<String> response = await _client.post<String>(
57+
uri,
58+
options: Options(headers: headers),
59+
data: file,
60+
onSendProgress: progressCallback,
61+
);
5862
if (response.statusCode == 201) {
5963
final Map<String, dynamic> map = json.decode(response.data);
6064
url = map['url'].toString();

0 commit comments

Comments
 (0)