speed up file uploads
This commit is contained in:
@@ -23,6 +23,17 @@ Future<Map> getClaims({bool refreshIdToken = false}) async {
|
||||
return idToken.claims;
|
||||
}
|
||||
|
||||
// returns list of url
|
||||
Future<List<String>> uploadFiles(String path, List<File> files,
|
||||
{String fileName}) async {
|
||||
List<Future<String>> fu = [];
|
||||
for (File f in files) {
|
||||
Future<String> u = uploadStorage(path, f);
|
||||
fu.add(u);
|
||||
}
|
||||
return Future.wait(fu);
|
||||
}
|
||||
|
||||
Future<String> uploadStorage(String path, File file, {String fileName}) async {
|
||||
if (fileName == null) {
|
||||
fileName = Uuid().v4();
|
||||
|
||||
@@ -255,11 +255,11 @@ class PackageModel extends BaseModel {
|
||||
if (files.length > uploadPhotoLimit)
|
||||
throw Exception("Exceed number of file upload");
|
||||
package.photoUrls = package.photoUrls == null ? [] : package.photoUrls;
|
||||
for (File f in files) {
|
||||
String path = Path.join(pkg_files_path);
|
||||
String url = await uploadStorage(path, f);
|
||||
String path = Path.join(pkg_files_path);
|
||||
List<String> urls = await uploadFiles(path, files);
|
||||
urls.forEach((url) {
|
||||
package.photoUrls.add(url);
|
||||
}
|
||||
});
|
||||
}
|
||||
return Services.instance.packageService.createReceiving(package);
|
||||
}
|
||||
@@ -284,11 +284,11 @@ class PackageModel extends BaseModel {
|
||||
if (count > uploadPhotoLimit)
|
||||
throw Exception("Exceed number of file upload");
|
||||
package.photoUrls = package.photoUrls == null ? [] : package.photoUrls;
|
||||
for (File f in files) {
|
||||
String path = Path.join(pkg_files_path);
|
||||
String url = await uploadStorage(path, f);
|
||||
String path = Path.join(pkg_files_path);
|
||||
List<String> urls = await uploadFiles(path, files);
|
||||
urls.forEach((url) {
|
||||
package.photoUrls.add(url);
|
||||
}
|
||||
});
|
||||
}
|
||||
await Services.instance.packageService.updateReceiving(package);
|
||||
}
|
||||
@@ -314,11 +314,11 @@ class PackageModel extends BaseModel {
|
||||
if (count > uploadPhotoLimit)
|
||||
throw Exception("Exceed number of file upload");
|
||||
package.photoUrls = package.photoUrls == null ? [] : package.photoUrls;
|
||||
for (File f in files) {
|
||||
String path = Path.join(pkg_files_path);
|
||||
String url = await uploadStorage(path, f);
|
||||
String path = Path.join(pkg_files_path);
|
||||
List<String> urls = await uploadFiles(path, files);
|
||||
urls.forEach((url) {
|
||||
package.photoUrls.add(url);
|
||||
}
|
||||
});
|
||||
package.photoUrls.removeWhere((e) => deletedUrls.contains(e));
|
||||
}
|
||||
await Services.instance.packageService.updateProcessing(package);
|
||||
|
||||
Reference in New Issue
Block a user