angularjswordpresswordpress-rest-apiionic-v1

Wordpress upload multiple image using custom endpoint rest api (ionic as enduser)


I want to upload multiple image to wordpress using ionic(angularjs).With custom endpoint rest api.

I tryed using ionic file transfer but its not working.The api endpoint was "example.com/wp-json/wc/v2/media" it says "Sorry, you are not allowed to create posts as this user"

Thats why i want use custom endpoint restapi and file path save into usermeta data

Any solution ???Or Advise


Solution

  • My advice

    Wordpress is simply saying you need to have at least the minimum access level needed to upload media files.

    To achieve this you need to implement authentication. Login with admin details.

    Two popular kinds of authentication through the rest api are:

    1. JWT authentication ( recommended ) https://wordpress.org/plugins/jwt-authentication-for-wp-rest-api/

    2. basic authentication ( discouraged for security reasons ) https://www.cloudways.com/blog/setup-basic-authentication-in-wordpress-rest-api/

    There is also cookie authentication. But this can be frustrating in PWAs, like ionic.

    I recommend JWT authentication.

    If you do not want authentication

    You can reduce the access level for the media rest endpoint by enabling the permission for basic user roles ( e.g subscriber , on woocommerce customer) .

    Check out this plugin through which you can update permissions https://wordpress.org/plugins/members/

    Warning: discarding authentication will allow anyone who knows your endpoint to upload files. So be careful.