File upload testing

This commit is contained in:
Elias Müller 2023-05-20 23:30:36 +02:00
parent 9a1247de5f
commit 3adc3bcf88
3 changed files with 131 additions and 11 deletions

View File

@ -1,11 +1,19 @@
import 'dart:developer';
import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:loader_overlay/loader_overlay.dart';
import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/cacheableFile.dart'; import 'package:marianum_mobile/api/marianumcloud/webdav/queries/listFiles/cacheableFile.dart';
import 'package:marianum_mobile/widget/errorView.dart'; import 'package:marianum_mobile/widget/errorView.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../../api/marianumcloud/webdav/queries/listFiles/listFilesCache.dart'; import '../../../api/marianumcloud/webdav/queries/listFiles/listFilesCache.dart';
import '../../../api/marianumcloud/webdav/queries/listFiles/listFilesResponse.dart'; import '../../../api/marianumcloud/webdav/queries/listFiles/listFilesResponse.dart';
import '../../../api/marianumcloud/webdav/webdavApi.dart';
import '../../../data/files/filesProps.dart'; import '../../../data/files/filesProps.dart';
import '../../../widget/filePick.dart';
import 'fileElement.dart'; import 'fileElement.dart';
class Files extends StatefulWidget { class Files extends StatefulWidget {
@ -91,7 +99,9 @@ class _FilesState extends State<Files> {
actions: [ actions: [
IconButton( IconButton(
icon: const Icon(Icons.search), icon: const Icon(Icons.search),
onPressed: () => {}, onPressed: () => {
// TODO implement search
},
), ),
PopupMenuButton<bool>( PopupMenuButton<bool>(
icon: Icon(currentSortDirection ? Icons.text_rotate_up : Icons.text_rotation_down), icon: Icon(currentSortDirection ? Icons.text_rotate_up : Icons.text_rotation_down),
@ -137,13 +147,88 @@ class _FilesState extends State<Files> {
), ),
], ],
), ),
body: data == null ? const Center(child: CircularProgressIndicator()) : data!.files.isEmpty ? const ErrorView(icon: Icons.folder_off_rounded, text: "Der Ordner ist leer") : ListView.builder( floatingActionButton: FloatingActionButton(
onPressed: () {
showDialog(context: context, builder: (context) {
return SimpleDialog(
children: [
ListTile(
leading: const Icon(Icons.folder),
title: const Text("Neuer Ordner"),
onTap: () {
WebdavApi.webdav.then((webdav) {
webdav.mkdirs("/MarianumMobileTest");
});
},
),
ListTile(
leading: const Icon(Icons.file_open),
title: const Text("Aus Dateien auswählen"),
onTap: () {
context.loaderOverlay.show();
FilePick.documentPick().then((value) {
log(value ?? "?");
mediaUpload(value);
});
Navigator.of(context).pop();
},
),
ListTile(
leading: const Icon(Icons.image),
title: const Text("Aus Gallerie auswählen"),
onTap: () {
context.loaderOverlay.show();
FilePick.galleryPick().then((value) {
log(value?.path ?? "?");
mediaUpload(value?.path);
});
Navigator.of(context).pop();
},
),
],
);
});
},
child: const Icon(Icons.upload),
),
body: data == null ? const Center(child: CircularProgressIndicator()) : data!.files.isEmpty ? const ErrorView(icon: Icons.folder_off_rounded, text: "Der Ordner ist leer") : LoaderOverlay(
child: ListView.builder(
itemCount: files.length, itemCount: files.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
CacheableFile file = files.toList().skip(index).first; CacheableFile file = files.toList().skip(index).first;
return FileElement(file, widget.path); return FileElement(file, widget.path);
}, },
), ),
)
); );
} }
void mediaUpload(String? path) async {
if(path == null) {
context.loaderOverlay.hide();
return;
}
SharedPreferences preferences = await SharedPreferences.getInstance();
WebDavClient client = NextcloudClient("https://cloud.marianum-fulda.de/", username: preferences.getString("username"), password: preferences.getString("password"), loginName: preferences.getString("username")).webdav;
log("UPLOAD STARTING: $path");
File file = File(path);
showDialog(
context: context,
builder: (context) {
return SimpleDialog(
children: [
Image.memory(file.readAsBytesSync()),
],
);
},
);
client.upload(file.readAsBytesSync(), "/${file.path.split(Platform.pathSeparator).last}").then((value) {
log("UPLOADED ${value.statusCode}");
context.loaderOverlay.hide();
});
}
} }

30
lib/webdavtest.dart Normal file
View File

@ -0,0 +1,30 @@
import 'dart:io';
import 'package:nextcloud/nextcloud.dart';
// NOT WORKING curl -H 'Transfer-Encoding: chunked' -H 'Content-Type: image/png' --compressed -u goldbaja -T /home/elias/Bilder/robotikmeme.png https://cloud.marianum-fulda.de/remote.php/webdav/some-image.png
// WORKS curl -H 'Transfer-Encoding: chunked' -H 'Content-Type: image/png' --compressed -u minetec -T /home/elias/Bilder/robotikmeme.png https://mhsl.eu/cloud/remote.php/webdav/some-image.png
void main() async {
print("HELLO WORLD");
WebDavClient client = NextcloudClient("https://cloud.marianum-fulda.de", username: "xxx", password: "xxx", loginName: "xxx").webdav;
final fileBytes = File("/home/elias/Bilder/robotikmeme.png").readAsBytesSync();
print(fileBytes.length);
HttpClientResponse response = await client.upload(fileBytes, "menue/test.png");
print(response.statusCode);
await Future.delayed(const Duration(seconds: 5)); // Wait a bit, just in case
final responses = (await client.ls(
'/menue/',
prop: WebDavPropfindProp.fromBools(
ocsize: true,
),
)).responses;
print("Filesize local: ${fileBytes.length}");
print("Filesize on Server: ${responses.singleWhere((final response) => response.href!.endsWith('/menue/test.png')).propstats.first.prop.ocsize}");
}

View File

@ -28,6 +28,15 @@ environment:
# dependencies can be manually updated by changing the version numbers below to # dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer # the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`. # versions available, run `flutter pub outdated`.
dependency_overrides:
xml: ^6.2.2
dynamite_runtime:
git:
url: https://github.com/provokateurin/nextcloud-neon
path: packages/dynamite/dynamite_runtime
ref: 482bff006d4338964c0704600c50434fe76a19b2
dependencies: dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
@ -53,7 +62,7 @@ dependencies:
git: git:
url: https://github.com/provokateurin/nextcloud-neon url: https://github.com/provokateurin/nextcloud-neon
path: packages/nextcloud path: packages/nextcloud
ref: 68624545e6ef45e6c4d07bf76addade067479683 ref: 482bff006d4338964c0704600c50434fe76a19b2
flutter_launcher_icons: ^0.13.1 flutter_launcher_icons: ^0.13.1
pretty_json: ^2.0.0 pretty_json: ^2.0.0
cached_network_image: ^3.2.3 cached_network_image: ^3.2.3
@ -74,10 +83,6 @@ dependencies:
package_info: ^2.0.2 package_info: ^2.0.2
syncfusion_flutter_calendar: ^21.2.4 syncfusion_flutter_calendar: ^21.2.4
dependency_overrides:
xml: ^6.2.2
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter