2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-16 20:25:26 +00:00

Allow file fields for api forms

This commit is contained in:
Oliver
2021-08-16 20:22:05 +10:00
parent e108598557
commit 8bca501fc4
5 changed files with 97 additions and 18 deletions

View File

@ -73,7 +73,7 @@ class InvenTreeModel {
return {};
}
Future<void> createForm(BuildContext context, String title, {Map<String, dynamic> fields=const{}, Map<String, dynamic> data=const {}, Function(dynamic)? onSuccess}) async {
Future<void> createForm(BuildContext context, String title, {String fileField = "", Map<String, dynamic> fields=const{}, Map<String, dynamic> data=const {}, Function(dynamic)? onSuccess}) async {
if (fields.isEmpty) {
fields = formFields();
@ -87,6 +87,7 @@ class InvenTreeModel {
modelData: data,
onSuccess: onSuccess,
method: "POST",
fileField: fileField,
);
}
@ -511,7 +512,7 @@ class InvenTreeAttachment extends InvenTreeModel {
Future<bool> uploadAttachment(File attachment, {String comment = "", Map<String, String> fields = const {}}) async {
final http.StreamedResponse response = await InvenTreeAPI().uploadFile(
final APIResponse response = await InvenTreeAPI().uploadFile(
URL,
attachment,
method: 'POST',
@ -519,11 +520,7 @@ class InvenTreeAttachment extends InvenTreeModel {
fields: fields
);
if (response.statusCode == 200 || response.statusCode == 201) {
return true;
} else {
return false;
}
return response.successful();
}
Future<void> downloadAttachment() async {

View File

@ -356,19 +356,14 @@ class InvenTreePart extends InvenTreeModel {
Future<bool> uploadImage(File image) async {
// Upload file against this part
final http.StreamedResponse response = await InvenTreeAPI().uploadFile(
final APIResponse response = await InvenTreeAPI().uploadFile(
url,
image,
method: 'PATCH',
name: 'image',
);
if (response.statusCode != 200) {
print("uploadImage returned ${response.statusCode} at '${url}'");
return false;
}
return true;
return response.successful();
}
// Return the "starred" status of this part