mirror of
https://github.com/HendrikRauh/inventree-app.git
synced 2026-01-13 19:46:25 +00:00
Function to upload file via API
This commit is contained in:
parent
6f12929057
commit
7bfc26b5a0
1 changed files with 24 additions and 1 deletions
25
lib/api.dart
25
lib/api.dart
|
|
@ -276,6 +276,30 @@ class InvenTreeAPI {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Upload a file to the given URL
|
||||||
|
*/
|
||||||
|
Future<http.StreamedResponse> uploadFile(String url, File f, {String name = "attachment", Map<String, String> fields}) async {
|
||||||
|
var _url = makeApiUrl(url);
|
||||||
|
|
||||||
|
var request = http.MultipartRequest('POST', Uri.parse(_url));
|
||||||
|
|
||||||
|
request.headers.addAll(defaultHeaders());
|
||||||
|
|
||||||
|
fields.forEach((String key, String value) {
|
||||||
|
request.fields[key] = value;
|
||||||
|
});
|
||||||
|
|
||||||
|
var _file = await http.MultipartFile.fromPath(name, f.path);
|
||||||
|
|
||||||
|
request.files.add(_file);
|
||||||
|
|
||||||
|
var response = await request.send();
|
||||||
|
|
||||||
|
return response;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Perform a POST request
|
// Perform a POST request
|
||||||
Future<http.Response> post(String url, {Map<String, dynamic> body}) async {
|
Future<http.Response> post(String url, {Map<String, dynamic> body}) async {
|
||||||
|
|
||||||
|
|
@ -322,7 +346,6 @@ class InvenTreeAPI {
|
||||||
var headers = Map<String, String>();
|
var headers = Map<String, String>();
|
||||||
|
|
||||||
headers[HttpHeaders.authorizationHeader] = _authorizationHeader();
|
headers[HttpHeaders.authorizationHeader] = _authorizationHeader();
|
||||||
//headers['Authorization'] = _authorizationHeader();
|
|
||||||
|
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue