#1 2022-01-19 21:08:30


Having trouble getting URL of uploaded image via API

I'm attempting to use the API to upload an image, and then store the URL of the image that was uploaded, but I'm having trouble. The image uploads fine, and I get back the image_id. When I then try to use pwg.images.getInfo, I get a "401 Unauthorized" even though my login status is 'admin'. After several minutes, the API call will work and I get back the image info.

Looking at the Piwigo code, this appears to happen because the image is in the 'lounge' buffer, and it seemingly is not considering me an admin when I make the getInfo request. I tried using the 'pwg.images.uploadCompleted' and 'pwg.images.emptyLounge' but those also give "Unauthorized" responses.

Below is a session I made using curl. My other attempts have been using Ruby and Rest-client, with the same results. I'd like to know if there is some way to either get the URL of an uploaded image (original, not a derivative) or what I'm doing incorrectly here.

>curl -i -X POST -F method="pwg.session.login" -F username=USER -F password=PASS -c pwgcookie "https:HOST/ws.php?format=json"


>curl -b pwgcookie -i -X GET "https:HOST/ws.php?format=json&method=pwg.session.getStatus"

{"stat":"ok","result":{"username":"guest","status":"guest","theme":"modus","language":"en_GB","pwg_token":"TOKEN","charset":"utf-8","current_datetime":"2022-01-19 19:29:01","version":"12.0.0","available_sizes":["square","thumb","2small","xsmall","small","medium","large","xlarge","xxlarge"]}}

(Not sure if this is a bug or not, or whether it's related to this issue, but the first response gives a valid token, but reports status & user as 'guest'. I have to send the getStatus call a second time to be sure.)

>curl -b pwgcookie -i -X GET "https:HOST/ws.php?format=json&method=pwg.session.getStatus"

{"stat":"ok","result":{"username":"USER","status":"admin","theme":"modus","language":"en_GB","pwg_token":"TOKEN","charset":"utf-8","current_datetime":"2022-01-19 19:29:08","version":"12.0.0","available_sizes":["square","thumb","2small","xsmall","small","medium","large","xlarge","xxlarge"],"upload_file_types":"jpg,jpeg,png,gif","upload_form_chunk_size":500}

>curl -b pwgcookie -i -X POST -F method="pwg.images.upload" -F file="@bw01.png" -F name="test bw" -F category=99 -F pwg_token="TOKEN" "https:HOST/ws.php?format=json"

{"stat":"ok","result":{"image_id":12345,"src":"https:HOST\/i.php?\/upload\/2022\/01\/19\/20220119193020-cc92421a-th.png","square_src":"https:\/\HOST\/i.php?\/upload\/2022\/01\/19\/20220119193020-cc92421a-sq.png","name":"test bw","category":{"id":99,"nb_photos":"26","label":"Community \/ USER \/ SUB1 \/ SUB2"}}}

>curl -b pwgcookie -i -X GET "https:HOST/ws.php?format=json&method=pwg.images.uploadCompleted&image_id=12345&category_id=99"

{"stat":"fail","err":401,"message":"Access denied"}

I try using POST instead:

>curl -b pwgcookie -i -X POST -F method="pwg.images.uploadCompleted" -F image_id=12345 -F category_id=99 "https:HOST/ws.php?format=json"

{"stat":"fail","err":401,"message":"Access denied"}

I try leaving off the category id:

>curl -b pwgcookie -i -X GET "https:HOST/ws.php?format=json&method=pwg.images.uploadCompleted&image_id=12345"

{"stat":"fail","err":401,"message":"Access denied"}

>curl -b pwgcookie -i -X GET "https:HOST/ws.php?format=json&method=pwg.images.getInfo&image_id=12345"

{"stat":"fail","err":401,"message":"Access denied"}

I then repeat the previous call every 20 seconds until I get a valid response. It takes about 2 - 5 minutes.

{"stat":"ok","result":{"id":12345,"file":"test bw","date_available":"2022-01-19 19:30:20","date_creation":null,"name":"test bw","comment":null,"author":null,"hit":0,"filesize":0,"width":32,"height":32,"coi":null,"representative_ext":null,"date_metadata_update":"2022-01-19","rating_score":null,"level":"0","md5sum":"cc92...

Last edited by Kangra (2022-01-19 21:13:12)



Board footer

Powered by FluxBB

github twitter newsletter Donate © 2002-2024 · Contact