Skip to content

Commit e8bbc24

Browse files
committed
fixed upload error
1 parent f747221 commit e8bbc24

6 files changed

Lines changed: 18 additions & 58 deletions

File tree

lib/api/ImageAPI.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import 'dart:io';
33

44
import 'package:dio/dio.dart';
55
import 'package:ext_storage/ext_storage.dart';
6-
import 'package:flutter/cupertino.dart';
76
import 'package:flutter/material.dart';
87
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
98
import 'package:path_provider/path_provider.dart';

lib/services/UploadStatusProvider.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ class UploadStatusNotifier extends ChangeNotifier {
2626
return "$_current/$_max";
2727
}
2828

29+
void reset() {
30+
_max = 0;
31+
_progress = 0;
32+
_current = 0;
33+
_status = false;
34+
}
35+
2936

3037
set max(int value) {
3138
_max = value;

lib/services/upload/Uploader.dart

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ class Uploader {
7979
}
8080
uploadStatusProvider.current++;
8181
}
82+
uploadStatusProvider.reset();
8283
} on DioError catch (e) {
8384
print(e.message);
84-
uploadStatusProvider.status = false;
85+
uploadStatusProvider.reset();
8586
ScaffoldMessenger.of(context).hideCurrentSnackBar();
8687
ScaffoldMessenger.of(context).showSnackBar(errorSnackBar(context, appStrings(context).uploadError_title));
8788
}
@@ -91,48 +92,11 @@ class Uploader {
9192
await communityUploadCompleted(uploadedImages, int.parse(category));
9293
} on DioError catch (e) {
9394
print(e.message);
94-
uploadStatusProvider.status = false;
9595
}
9696

97-
uploadStatusProvider.status = false;
98-
uploadStatusProvider.max = 0;
99-
uploadStatusProvider.current = 0;
100-
10197
await _showUploadNotification(result);
10298
}
10399

104-
void upload(XFile photo, String category) async {
105-
Map<String, String> queries = {"format":"json", "method": "pwg.images.upload"};
106-
List<int> imageData = await photo.readAsBytes();
107-
108-
Dio dio = new Dio(
109-
BaseOptions(
110-
baseUrl: API.prefs.getString("base_url"),
111-
),
112-
);
113-
114-
FormData formData = FormData.fromMap({
115-
"category": category,
116-
"pwg_token": API.prefs.getString("pwg_token"),
117-
"file": MultipartFile.fromBytes(
118-
imageData,
119-
filename: photo.path.split('/').last,
120-
),
121-
"name": photo.path.split('/').last,
122-
});
123-
124-
Response response = await dio.post("ws.php",
125-
data: formData,
126-
queryParameters: queries,
127-
);
128-
129-
if (response.statusCode == 200) {
130-
print('Upload ${response.data}');
131-
if(json.decode(response.data)["stat"] == "ok") {}
132-
} else {
133-
print("Request failed: ${response.statusCode}");
134-
}
135-
}
136100
Future<Response> uploadChunk(BuildContext context, XFile photo,
137101
String category, Map<String, dynamic> info,
138102
Function(double) onProgress,
@@ -142,8 +106,8 @@ class Uploader {
142106
"method": "pwg.images.uploadAsync"
143107
};
144108
Map<String, dynamic> fields = {
145-
'username': API.prefs.getString("username"),
146-
'password': API.prefs.getString("password"),
109+
'username': await API.storage.read(key: "username"),
110+
'password': await API.storage.read(key: "password"),
147111
'filename': photo.path.split('/').last,
148112
'category': category,
149113
};

lib/services/upload/chunked_uploader.dart

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ class UploadRequest {
8383
}
8484

8585
for (int i = 0; i < _chunksCount; i++) {
86-
// print("${i+1} | $_chunksCount");
8786
final start = _getChunkStart(i);
8887
final end = _getChunkEnd(i);
8988
final chunkStream = _getChunkStream(start, end);
@@ -96,20 +95,13 @@ class UploadRequest {
9695
"file": MultipartFile(chunkStream, end - start, filename: fileName),
9796
if (data != null) ...data
9897
});
99-
try {
100-
finalResponse = await dio.request(
101-
path,
102-
data: formData,
103-
queryParameters: params,
104-
options: Options(
105-
method: method,
106-
contentType: contentType
107-
),
108-
onSendProgress: (current, total) => _updateProgress(i, current, total),
109-
);
110-
} catch (e) {
111-
print(e);
112-
}
98+
finalResponse = await dio.request(
99+
path,
100+
data: formData,
101+
queryParameters: params,
102+
options: Options(method: method, contentType: contentType),
103+
onSendProgress: (current, total) => _updateProgress(i, current, total),
104+
);
113105
}
114106
return finalResponse;
115107
}

lib/views/ImageViewPage.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:better_player/better_player.dart';
21
import 'package:cached_network_image/cached_network_image.dart';
32
import 'package:flutter/material.dart';
43
import 'package:icon_shadow/icon_shadow.dart';

pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ dependencies:
5757
cached_network_image: ^3.0.0
5858
better_player: ^0.0.79
5959
video_player: ^2.2.10
60-
video_thumbnail: ^0.4.6
6160
wakelock: ^0.5.6
6261

6362
dev_dependencies:

0 commit comments

Comments
 (0)