• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

    • 😌 This community is user driven. Be polite with other users.
    • 👉 Is required to purchase a Chevereto license to participate in this community (doesn't apply to Pre-sales).
    • 💸 Purchase a Pro Subscription to get access to active software support and faster ticket response times.

ShareX and Chevereto

Rodolfo

⭐ Chevereto Godlike
Chevereto Staff
Administrator
Hey guys, I've made a guide to use Chevereto with ShareX. With this tool you can upload directly from your desktop. You can upload images, screen captures, etc. You can even define a hotkey for this.


We will use this topic for questions and concerns about using Chevereto with ShareX.
 
Last edited:

anmolgill

Chevereto Member
i am trying to work with user api not working
http://shareimg.eu/myapi/1/upload/?.../uploads/2013/01/google_chrome.png&format=txt can u please check i have edited file as listed in docs

PHP:
<?php

/* --------------------------------------------------------------------

  Chevereto
  http://chevereto.com/

  @author    Rodolfo Berrios A. <http://rodolfoberrios.com/>
            <inbox@rodolfoberrios.com>

  Copyright (C) Rodolfo Berrios A. All rights reserved.
 
  BY USING THIS SOFTWARE YOU DECLARE TO ACCEPT THE CHEVERETO EULA
  http://chevereto.com/license

  --------------------------------------------------------------------- */

  /* API v1 : PLEASE NOTE
    
     This API v1 is currently just a bridge to port to Chevereto 3 the API from Chevereto 2.
     From now on Chevereto 2 API will be named API v1
    
     In future releases there will be an API v2 which will add methods like create user, create albums, etc.
    
  */
 
$route = function($handler) {
    try {
        $version = $handler->request[0];
        $action = $handler->request[1];
       
        if(is_null(CHV\getSetting('api_v1_key')) or CHV\getSetting('api_v1_key') == '') {
            throw new Exception("API v1 key can't be null. Go to your dashboard and set the API v1 key.", 0);
        }
       
        if(!G\timing_safe_compare('315056', $_REQUEST['key'])) {
            throw new Exception("Invalid API v1 key.", 100);
        }
       
        if(!in_array($version, [1])) {
            throw new Exception('Invalid API version.', 110);
        }
       
        $version_to_actions = [
            1 => ['upload']
        ];
       
        if(!in_array($action, $version_to_actions[$version])) {
            throw new Exception('Invalid API action.', 120);
        }
       
        // API V1 upload
        $source = isset($_FILES['source']) ? $_FILES['source'] : $_REQUEST['source'];
       
        if(is_null($source)) {
            throw new Exception('Empty upload source.', 130);
        }

        if($_FILES['source']['tmp_name']) { // File?
            $source = $_FILES['source'];
            $type = 'file';
        } else {
            if(!G\is_image_url($source)) {
           
                // Base64 comes from POST?
                if($_SERVER['REQUEST_METHOD'] !== 'POST') {
                    throw new Exception('Uploading source base64 must be done using POST method.', 130);
                }
               
                // Fix the $source base64 string
                $source = trim(preg_replace('/\s+/', '', $source));
               
                // From _GET source should be urlencoded base64
                if(!G\timing_safe_compare(base64_encode(base64_decode($source)), $source)){
                    throw new Exception('Invalid base64 string.', 120);
                }
               
                // Set the API temp file       
                $api_temp_file = @tempnam(sys_get_temp_dir(), 'chvtemp');
               
                if(!$api_temp_file or !@is_writable($api_temp_file)) {
                    throw new UploadException("Can't get a tempnam.", 200);
                }
                   
                $fh = fopen($api_temp_file, 'w');
                stream_filter_append($fh, 'convert.base64-decode', STREAM_FILTER_WRITE);
                if(!@fwrite($fh, $source)) {
                    throw new Exception('Invalid base64 string.', 130);
                } else {
                    // Since all the validations works with $_FILES, we're going to emulate it.
                    $source = array(
                        'name'        => G\random_string(12).'.jpg',
                        'type'        => 'image/jpeg',
                        'tmp_name'    => $api_temp_file,
                        'error'        => 'UPLOAD_ERR_OK',
                        'size'        => '1'
                    );
                }
                fclose($fh);
            }
        }
       
        $uploaded_id = CHV\Image::uploadToWebsite($source, User::getSingle('shareimg', 'username'), NULL);
        $json_array['status_code'] = 200;
        $json_array['success'] = array('message' => 'image uploaded', 'code' => 200);
        $json_array['image'] = CHV\Image::formatArray(CHV\Image::getSingle($uploaded_id, false, false), true);
       
        if($version == 1) {
            switch($_REQUEST['format']) {
                default:
                case 'json':
                default:
                    G\Render\json_output($json_array);
                    break;
                case 'txt':
                    echo $json_array['image']['url'];
                    break;
                case 'redirect':
                    if($json_array['status_code'] == 200) {
                        $redirect_url = $json_array['image']['url_viewer'];
                        header("Location: $redirect_url");
                    } else {
                        die($json_array['status_code']);
                    }
                    break;
            }
            die();
        } else {
            G\Render\json_output($json_array);
        }
       
    } catch(Exception $e) {
        $json_array = G\json_error($e);
        if($version == 1) {
            switch($_REQUEST['format']) {
                default:
                case 'json':
                default:
                    G\Render\json_output($json_array);
                    break;
                case 'txt':
                case 'redirect':
                    die($json_array['error']['message']);
                    break;
            }
        } else {
            G\Render\json_output($json_array);
        }
       
    }
};
 

Rodolfo

⭐ Chevereto Godlike
Chevereto Staff
Administrator
The code from the docs was wrong, this:
PHP:
CHV\Image::uploadToWebsite($source, User::getSingle('shareimg', 'username'), NULL);

Should be this:

PHP:
CHV\Image::uploadToWebsite($source, CHV\User::getSingle('shareimg', 'username'), NULL);
 

Rodolfo

⭐ Chevereto Godlike
Chevereto Staff
Administrator
Sure, but you need to manually add the service endpoints. The original guide was all manual, at this time I don't remember the exact parameters but I remember that you need to add custom service and fill some boxes.
 

djcyry

Chevereto Member
Hey guys, I've made a guide to use Chevereto with ShareX. With this tool you can upload directly from your desktop. You can upload images, screen captures, etc. You can even define a hotkey for this.

https://chevereto.com/docs/sharex

We will use this topic for questions and concerns about using Chevereto with ShareX.


I have this problem , the chevereto api and url is ok :

Code:
Message:
The remote server returned an error: (400) Bad Request.

Response:
{"status_code":400,"error":{"message":"Flood detected. You can only upload 50 images per minute","code":130,"context":"CHV\\UploadException"},"status_txt":"Bad Request"}

StackTrace:
   at System.Net.HttpWebRequest.GetResponse()
   at ShareX.UploadersLib.Uploader.UploadData(Stream dataStream, String url, String fileName, String fileFormName, Dictionary`2 arguments, NameValueCollection headers, CookieCollection cookies, ResponseType responseType, HttpMethod method, String requestContentType, String metadata)
 

evilmoe2

Not needed
Ok. was the flood protecion .
Can i disabled for admins and users ? thx

Its disabled for admin by default but API v1 does not support user authentification anyway.

You can increase the values for the flood protection, check your dashboard -> settings -> flood protection.
 

jefflin

Chevereto Member
Is it posible to record the original URL on Description or somewhere on my Chevereto when user post the image ?

Like the pinterest, then I can know where the orignal image post from.
 
Last edited:

SirMoo

💖 Chevereto Fan
Is it posible to record the original URL on Description or somewhere on my Chevereto when user post the image ?

Like the pinterest, then I can know where the orignal image post from.
I don't believe so. The current API is rather 'dumb' in the sense that it's only task is to upload images without a care.
 

geekbear

Chevereto Member
Pro
Hi, when i want use shareX 10.9.1

URL : https://geekpics.fr/image
API KEY : (MY KEY)

I have this problem.

StackTrace:
à System.Net.HttpWebRequest.GetResponse()
à ShareX.UploadersLib.Uploader.UploadData(Stream dataStream, String url, String fileName, String fileFormName, Dictionary`2 arguments, NameValueCollection headers, CookieCollection cookies, ResponseType responseType, HttpMethod method, String requestContentType, String metadata)
 

vova8861

Chevereto Member
Hello Tell me please. How do I build a program with the exe extension from the ShareX source?


From this get this here
 

tunny

Chevereto Member
Did someone of you guys tried this out?

https://chevereto.com/docs/api-v1#api-user

PHP:
API user upload workaround
API V1 one doesn't have a way to upload images associated with a given user but Chevereto comes ready for route overriding and you can easily customize your own API that can accomplish this task. Copy the default app/routes/route.api.php file to something like app/routes/overrides/route.myapi.php folder. We will do our job in this new route.myapi.php file.

Change this:

CHV\Image::uploadToWebsite($source);
To this (replace jesse with the target username or user_id):

// This will upload images to 'jesse' account
CHV\Image::uploadToWebsite($source, 'jesse');
By doing this the /myapi route (Custom API) will now upload images in the name of that user. If you want to use a different API key in this new customized API simply change this:

!G\timing_safe_compare(CHV\getSetting('api_v1_key'), $_REQUEST['key'])
To this:

!G\timing_safe_compare('NowThisIsAnotherAPIKEY!', $_REQUEST['key'])
By doing this you will be able to use the default API (/api) with one key and the customized API (/myapi) with another key.

Uploading to the Useraccount is working fine! But everytime i get this response from Sharex itself:
https://hastebin.com/awucajofix.xml

Any ideas guys?
 

Rodolfo

⭐ Chevereto Godlike
Chevereto Staff
Administrator
404 means "not found"... It means that the thing isn't resolving in that path.
 

caicaistay

Chevereto Member
Pro
我在3.0找到了这个route.api.PHP, 但是我现在已经升级到4.0了,这个php文件在哪里?
文档中的代码是错误的,这个:
PHP:
CHV\Image::uploadToWebsite($source, User::getSingle('shareimg', 'username'), NULL);

应该是这样的:

PHP:
CHV\Image::uploadToWebsite($source, CHV\User::getSingle('shareimg', '用户名'), NULL);
 

Rodolfo

⭐ Chevereto Godlike
Chevereto Staff
Administrator
我在3.0找到了这个route.api.PHP, 但是我现在已经升级到4.0了,这个php文件在哪里?
You don't need to edit anything. V4 includes user based API, the keys are available at the user settings.
 

caicaistay

Chevereto Member
Pro
您无需编辑任何内容。V4 包含基于用户的 API,密钥在用户设置中可用。
PHP CHV\Image::uploadToWebsite($source, User::getSingle('shareimg', 'username'), ~~~~ 可以直接上传到wp主题中的图床,但是更新到V4就不再像一如既往的方便,还没人开发过插件,好麻烦
您无需编辑任何内容。V4 包含基于用户的 API,密钥在用户设置中可用。
 
Top