Upload new Avatar via API

2 years 4 months ago #327385 by asierraserna
Upload new Avatar via API was created by asierraserna
Hello Joomlapolis Community!

I have been developing an app using react-native and using APIs I have been creating using COM_API.

So far, everything is going great, but now I am blocked by how to store an image uploaded from the app.

The app part is done, and the image is received by my API server perfectly fine, but I am trying to use CB APIs to store the Avatar in the best way possible.

I have been checking this class:
class CBfield_image extends cbFieldHandler in cb.core.php to see if I can use its functions to verify and store safely the image sent from the app, but I have not been able to do it.

In my API end-point I am calling all the CB framework and even the GJ framework to try to get to that class, but no luck so far:
// CB load
global $_CB_framework, $mainframe;

if ( defined( 'JPATH_ADMINISTRATOR' ) ) {
	if ( ! file_exists( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ) ) {
		return;
	}

	require_once( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' );
} else {
	if ( ! file_exists( $mainframe->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/plugin.foundation.php' ) ) {
		return;
	}

	require_once( $mainframe->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/plugin.foundation.php' );
}

cbimport( 'cb.html' );

if ( ! file_exists( $_CB_framework->getCfg( 'absolute_path' ) . '/components/com_comprofiler/plugin/user/plug_cbgroupjive/cbgroupjive.class.php' ) ) {
	return;
}

require_once( $_CB_framework->getCfg( 'absolute_path' ) . '/components/com_comprofiler/plugin/user/plug_cbgroupjive/cbgroupjive.class.php' );

I have tried via
CBuser::getMyInstance();

and have tried to get the CBuser::? methods available, hoping there is something like CBuser::updateAvatar($_FILE, $user) or something miraculous like that.

Please help :) :blush:

Cheers!

Please Log in to join the conversation.

2 years 4 months ago #327387 by krileon
Replied by krileon on topic Upload new Avatar via API
We don't provide a method for doing that. It expects a normal POST with the file input data existing in FILES global. Copy and modify the upload code in the commitFieldDataSave function of CBfield_image field class as needed. This will change when we convert the fields to Joomla fields though where it'll be easier to extract out an individual fields storage behavior.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

2 years 4 months ago #327388 by asierraserna
Replied by asierraserna on topic Upload new Avatar via API
Thank you for your mega fast answer!

That is exactly what I was thinking about doing, but wanted to check with you first.

You are an absolute magician! The more I learn about code, the more I like your solution.

Thank you very much for this awesome solution!

Alejandro
The following user(s) said Thank You: krileon

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.197 seconds

Facebook Twitter LinkedIn