File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -652,6 +652,34 @@ class WordPress {
652652 }
653653
654654// yahya - @mymakarim
655+
656+ async .Future <dynamic > uploadMedia (File image) async {
657+ final StringBuffer url = new StringBuffer (_baseUrl + URL_MEDIA );
658+ var file = image.readAsBytesSync ();
659+ final response = await http.post (
660+ url.toString (),
661+ headers: {
662+ "Content-Type" : "image/png" ,
663+ "Content-Disposition" : "form-data; filename=firstIg.png" ,
664+ "Authorization" : "${_urlHeader ['Authorization' ]}"
665+ },
666+ body: file,
667+ );
668+
669+ if (response.statusCode >= 200 && response.statusCode < 300 ) {
670+ return json.decode (response.body);
671+ } else {
672+ try {
673+ WordPressError err =
674+ WordPressError .fromJson (json.decode (response.body));
675+ throw err;
676+ } catch (e) {
677+ throw new WordPressError (message: response.body);
678+ }
679+ }
680+ }
681+
682+ // uploadMedia function added by: @GarvMaggu
655683
656684 async .Future <bool > createUser ({@required User user}) async {
657685 final StringBuffer url = new StringBuffer (_baseUrl + URL_USERS );
You can’t perform that action at this time.
0 commit comments