• Purchasing a license grants permission to use the software and to get Tech Support. A license purchase doesn't grant customization support.

API Image Title

BigBoiJefe

Network license
Beta tester
Joined
Apr 8, 2014
Messages
112
Points
68
Hi, i'm using the api, however, I need to know if there's a way to pass a title of the uploaded image? If this does not exist, how much to add this?
 

Rodolfo

Chevereto Developer
Chevereto Staff
Joined
Oct 7, 2008
Messages
15,628
Points
237
Location
Chevereto HQ
Website
rodolfoberrios.com
Like I said, is dead easy. How you want me to ask money for change one line?

In route.api.php this is the function that uploads the content to the website:

PHP:
$uploaded_id = CHV\Image::uploadToWebsite($source, NULL, NULL);

And if you dig the code in class.image.php you will notice which params this function accepts:
PHP:
public static function uploadToWebsite($source, $user, $params=[]) {

The third param ($params=[]) is an array which may contain additional data, if you scroll down a little bit you will see:
PHP:
            $image_insert_values = [
                'storage_mode'    => $storage_mode,
                'storage_id'    => $storage_id, // nota: real storage id
                'user_id'        => $user['id'],
                'album_id'        => NULL,
                'nsfw'            => $params['nsfw'],
                'category_id'    => $params['category_id'],
                'title'            => $params['title'],
                'description'    => $params['description'],
                'chain'            => $chain_value,
                'thumb_size'    => $image_thumb['fileinfo']['size'],
                'medium_size'    => $image_medium['fileinfo']['size'] ?: 0      
            ];
As you may notice, a lot of infomation can be injected just populating the $params array.


So this line in route.api.php:
PHP:
$uploaded_id = CHV\Image::uploadToWebsite($source, NULL, NULL);

Shoud be something like this:
PHP:
$uploaded_id = CHV\Image::uploadToWebsite($source, NULL, ['title' => $_REQUEST['title']]);

Where $_REQUEST['title'] comes from the request. And done, the title can be injected using the API.
 

BigBoiJefe

Network license
Beta tester
Joined
Apr 8, 2014
Messages
112
Points
68
Can I then add the user_id, category_id and album_id as well to the same request?

PHP:
$uploaded_id = CHV\Image::uploadToWebsite($source, NULL, ['title' => $_REQUEST['title']]['album_id' => $_REQUEST['album_id']]['category_id' => $_REQUEST['category_id']]['user_id' => $_REQUEST['id']]);
 

BigBoiJefe

Network license
Beta tester
Joined
Apr 8, 2014
Messages
112
Points
68
What about the user_id? I can't seem to figure that one out.
 

BigBoiJefe

Network license
Beta tester
Joined
Apr 8, 2014
Messages
112
Points
68
I see. I'd like to be able to pass the user_id just like the title. Is that something that can done?
 

Rodolfo

Chevereto Developer
Chevereto Staff
Joined
Oct 7, 2008
Messages
15,628
Points
237
Location
Chevereto HQ
Website
rodolfoberrios.com
Actually is easier than that... Check the function:

PHP:
    public static function uploadToWebsite($source, $user, $params=[]) {
       
        try {
           
            if($user) {
                switch(gettype($user)) {
                    case 'string':
                        $user = User::getSingle($user, 'username');
                    break;
                    case 'integer':
                        $user = User::getSingle($user);
                    break;
                }
            }
So you can pass $user directly as username or user id.
 

BigBoiJefe

Network license
Beta tester
Joined
Apr 8, 2014
Messages
112
Points
68
I'm missing something, if I use

PHP:
$uploaded_id = CHV\Image::uploadToWebsite($source,NULL,['title' => $_REQUEST['title']],['category_id' => $_REQUEST['category_id']]);
Then when I pass &title=blah&category_id=1 the actual status result shows "category_id":null
 

Rodolfo

Chevereto Developer
Chevereto Staff
Joined
Oct 7, 2008
Messages
15,628
Points
237
Location
Chevereto HQ
Website
rodolfoberrios.com
Your code is wrong. You are passing just the title in the $param array.

PHP:
$uploaded_id = CHV\Image::uploadToWebsite($source,NULL,['title' => $_REQUEST['title'],'category_id' => $_REQUEST['category_id']]);
 

BigBoiJefe

Network license
Beta tester
Joined
Apr 8, 2014
Messages
112
Points
68
Yes. You can pass anything. Just check the code and notice that the user_id must be passed as the second parameter of the function.
I can see that if I change NULL to 'Username', it does in fact upload to that username, however, I'm not looking to modify the php file everytime I need to change this.