• 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.
  • Chevereto Support CLST

    Support response

    Support checklist

Awaiting feedback Can't use API

uncledim

Chevereto Member
Hello,

I have some trouble to use API since i update from 2.1 to 3.5.4. (today)

I try different things but nothing works.

With php curl like this :

PHP:
$url = 'http://ipserveur/i/api/1/upload/';
$localFile = $_FILES[qqfile][tmp_name];
$fp = fopen($localFile, 'r');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url.'?key=mykey');
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 86400); // 1 Day Timeout
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
curl_setopt($ch, CURLOPT_BUFFERSIZE, 128);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localFile));
$result = curl_exec ($ch);
$info = curl_getinfo($ch);
print_r($info);
curl_close($ch);
echo json_encode(array('success'=>true,'retour_chevreto'=>$result));

Code:
Array
(
    [url] => http://ipserveur/i/api/1/upload/?key=mykey
    [content_type] => text/html; charset=utf-8
    [http_code] => 301
    [header_size] => 627
    [request_size] => 128
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.239818
    [namelookup_time] => 2.1E-5
    [connect_time] => 0.100852
    [pretransfer_time] => 0.100855
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => 0
    [upload_content_length] => 86433
    [starttransfer_time] => 0.239804
    [redirect_time] => 0
    [certinfo] => Array
        (
        )

)
{"success":true,"retour_chevreto":""}

or like this

PHP:
$url = 'http://ipserveur/i/api/1/upload/';
$fields = array(
            'key' => 'mykey',
            'source' => '@'.$_FILES[qqfile][tmp_name]
        );
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 20000);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_VERBOSE, true);

$result = curl_exec ($ch);
$info = curl_getinfo($ch);
print_r($info);
curl_close($ch);
echo json_encode(array('success'=>true,'retour_chevreto'=>$result));


Code:
Array
(
    [url] => http://ipserveur/i/api/1/upload/?key=mykey
    [content_type] => text/html; charset=utf-8
    [http_code] => 301
    [header_size] => 627
    [request_size] => 128
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.239818
    [namelookup_time] => 2.1E-5
    [connect_time] => 0.100852
    [pretransfer_time] => 0.100855
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => 0
    [upload_content_length] => 86433
    [starttransfer_time] => 0.239804
    [redirect_time] => 0
    [certinfo] => Array
        (
        )

)
{"success":true,"retour_chevreto":true}

I try with curl command line like this :

Code:
curl -v --form "source=@FriseMSTrefaite.png" "http://ipserveur/i/api/1/upload/?key=mykey"
* About to connect() to 151.236.24.202 port 80 (#0)
*   Trying ipserveur... connected
* Connected to ipserveur (ipserveur) port 80 (#0)
> POST /i/api/1/upload/?key=mykeyHTTP/1.1
> User-Agent: curl/7.21.0 (i486-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.15 libssh2/1.2.6
> Host: ipserveur
> Accept: */*
> Content-Length: 1163133
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------db62b1421c7e
>
< HTTP/1.1 100 Continue
< HTTP/1.1 301 Moved Permanently
< Date: Fri, 24 Oct 2014 17:14:20 GMT
< Server: Apache/2.2.16 (Debian)
< X-Powered-By: PHP/5.4.34-1~dotdeb.0
< Set-Cookie: PHPSESSID=m5585trpdnpgnemp1c15089k10; path=/
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
< Set-Cookie: KEEP_LOGIN=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/i/
< Set-Cookie: KEEP_LOGIN_SOCIAL=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/i/
< Location: http://ipserveur/i/login
< Vary: Accept-Encoding
< Content-Length: 0
< Content-Type: text/html; charset=utf-8
<
* Connection #0 to host ipserveur left intact
* Closing connection #0

Few more elements :

I can upload image directly from web interface

When i access with my browser to this url :


I have this feedback

{"status_code":400,"error":{"message":"Empty upload source.","code":130,"context":"Exception"},"status_txt":"Bad Request"}​



Honnestly i don't understand what i do wrong, bad server config, bad update chevereto bad ... I just notice i always have a 301 http code in return but why ?

If someone can help me, he's welcome : )

ps : Sorry for my bad english....
 
Last edited:
When i access with my browser to this url :

http://ipserveur/i/api/1/upload/?key=mykey

I have this feedback

{"status_code":400,"error":{"message":"Empty upload source.","code":130,"context":"Exception"},"status_txt":"Bad Request"}

That is why you are missing the "source". It should be:
PHP:
http://ipserveur/i/api/1/upload/?key=mykey&source=<SOURCE>

As the API states: Source can be a $_FILES resource, a base64 encoded image string or a image URL (not file:// or local resource locator).

For what I'm seeing, you are trying to use this with the server IP right? That is why you may have redirect issues but honestly with the input provided I can't test anything and unless you provide me a real key and a real website address I can't help you.
 
That is why you are missing the "source". It should be:
PHP:
http://ipserveur/i/api/1/upload/?key=mykey&source=<SOURCE>

As the API states: Source can be a $_FILES resource, a base64 encoded image string or a image URL (not file:// or local resource locator).

For what I'm seeing, you are trying to use this with the server IP right? That is why you may have redirect issues but honestly with the input provided I can't test anything and unless you provide me a real key and a real website address I can't help you.

Thans for answer.

I give you element in MP :)
 
Problem seems to be that the api route (/api) isn't allowed to be used in the private mode.

app/loader.php

This:
PHP:
$allowed_requests = ['login', 'image', 'album', 'page', 'account', 'connect'];

Should be this:
PHP:
$allowed_requests = ['api', 'login', 'image', 'album', 'page', 'account', 'connect'];
 
Back
Top