mirror of
				https://github.com/inventree/inventree-app.git
				synced 2025-10-30 21:05:42 +00:00 
			
		
		
		
	Merge pull request #48 from SchrodingersGat/part-photo-upload
Part photo upload
This commit is contained in:
		| @@ -62,11 +62,10 @@ class InvenTreeFileService extends FileService { | |||||||
| class InvenTreeAPI { | class InvenTreeAPI { | ||||||
|  |  | ||||||
|   // Minimum required API version for server |   // Minimum required API version for server | ||||||
|   static const _minApiVersion = 3; |   static const _minApiVersion = 6; | ||||||
|  |  | ||||||
|   // Endpoint for requesting an API token |   // Endpoint for requesting an API token | ||||||
|   static const _URL_GET_TOKEN = "user/token/"; |   static const _URL_GET_TOKEN = "user/token/"; | ||||||
|   static const _URL_GET_VERSION = ""; |  | ||||||
|  |  | ||||||
|   static const _URL_GET_ROLES = "user/roles/"; |   static const _URL_GET_ROLES = "user/roles/"; | ||||||
|  |  | ||||||
| @@ -518,16 +517,18 @@ class InvenTreeAPI { | |||||||
|    * Upload a file to the given URL |    * Upload a file to the given URL | ||||||
|    */ |    */ | ||||||
|   Future<http.StreamedResponse> uploadFile(String url, File f, |   Future<http.StreamedResponse> uploadFile(String url, File f, | ||||||
|       {String name = "attachment", Map<String, String> fields}) async { |       {String name = "attachment", String method="POST", Map<String, String> fields}) async { | ||||||
|     var _url = makeApiUrl(url); |     var _url = makeApiUrl(url); | ||||||
|  |  | ||||||
|     var request = http.MultipartRequest('POST', Uri.parse(_url)); |     var request = http.MultipartRequest(method, Uri.parse(_url)); | ||||||
|  |  | ||||||
|     request.headers.addAll(defaultHeaders()); |     request.headers.addAll(defaultHeaders()); | ||||||
|  |  | ||||||
|  |     if (fields != null) { | ||||||
|       fields.forEach((String key, String value) { |       fields.forEach((String key, String value) { | ||||||
|         request.fields[key] = value; |         request.fields[key] = value; | ||||||
|       }); |       }); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     var _file = await http.MultipartFile.fromPath(name, f.path); |     var _file = await http.MultipartFile.fromPath(name, f.path); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -301,8 +301,26 @@ class InvenTreePart extends InvenTreeModel { | |||||||
|       return img.isNotEmpty ? img : InvenTreeAPI.staticThumb; |       return img.isNotEmpty ? img : InvenTreeAPI.staticThumb; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     void uploadImage(File image) async { |     Future<bool> uploadImage(File image) async { | ||||||
|       // TODO |       // Upload file against this part | ||||||
|  |       final http.StreamedResponse response = await InvenTreeAPI().uploadFile( | ||||||
|  |         url, | ||||||
|  |         image, | ||||||
|  |         method: 'PATCH', | ||||||
|  |         name: 'image', | ||||||
|  |       ); | ||||||
|  |  | ||||||
|  |       if (response == null) { | ||||||
|  |         print("uploadImage returned null at '${url}'"); | ||||||
|  |         return false; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       if (response.statusCode != 200) { | ||||||
|  |         print("uploadImage returned ${response.statusCode} at '${url}'"); | ||||||
|  |         return false; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       return true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // Return the "starred" status of this part |     // Return the "starred" status of this part | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user