Announcement

#1 2015-01-06 14:17:50

ImageAdmin
Member
2014-12-24
3

API pwg.images.add problems

New Year Greetings,

Having uploaded an image in 2 versions (file and thumb) with pwg.images.addChunk, and verified that all chunkfiles are received on the server (public_html/piwigo/upload/buffer), the pwg.images.add reports: {"stat":"fail","err":1002,"message":"Missing parameters: data,position"}. I need help!

From the pwg.images.addChunk I get: {"stat":"ok","result":null}.

Here are some observations, then some questions:

A. The chunkfiles appear on the server as decoded from the Base64 string back to its original form, as the bytesize correspond with the original image. But the file sizes vary whether I use line-endings or not in the Base64 encoding.

B. The Piwigo web API explorer state under pwg.images.add:
Don't use "thumbnail_sum" and "high_sum", these parameters are here for backward compatibility. - whereas the document “pwg.images.add & pwg.images.addChunk” on the contrary promotes the use of  "thumbnail_sum" and optionally "high_sum".

C. The Piwigo web API explorer and the document “pwg.images.add & pwg.images.addChunk” disagree on which parameters are available:
- original_filename, check_uniqueness and image_id in the API explorer is not mentioned in the document, whereas file_sum in the document is not mentioned in the API explorer.

D. They also disagree on which parameters are mandatory versus optional.

I have now invested a full workweek of trying to make the API function, read the Forum for explanations, but still have problems. Can anybody give me some help or direction?

1. Should the md5sum of a chunkfile reflect the image it is chunking (eg. thumb or file), or should I use the same md5sum for all chunkfiles regardless of filetype? The latter must be the consequence if "thumbnail_sum" and "high_sum" should not be used. What md5sum should then be used?

2. Which parameters are minimum necessary with pwg.images.add? And what does check_uniqueness and image_id do? I really want to upload both high, file and thumb for each image.

The program talking to Piwigo is Xojo. I will happily share my code for handling the Piwigo API if I ever make it work. I am not current with PHP or Perl.

Piwigo version: 2.7.2
PHP version: 5.3.28
MySQL version: 5.5.40-cll

Offline

 

#2 2015-01-06 14:24:51

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: API pwg.images.add problems

Hi

use pwg.images.addSimple instead, the other one is kinda deprecated

also there is no need to upload thumbnails (they are ignored), only upload the full size image

Offline

 

#3 2015-01-06 14:26:14

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: API pwg.images.add problems

Offline

 

#4 2015-01-06 17:02:40

ImageAdmin
Member
2014-12-24
3

Re: API pwg.images.add problems

After spending a week on the addChunk method - and it is nowhere said in the docs that it is deprecated - this is quite an answer!

Couldn’t you please just give me a short direction in where to look for a solution?

I rejected pwg.images.addSimple because I couldn’t figure out how to upload the actual image within the API and the chunk method suits my need as I shall handle big images, all one by one.

mistic100 wrote:

... thumbnails (they are ignored), only upload the full size image

Is this valid for all methods or the addChunk one or addSimple?

Offline

 

#5 2015-01-07 16:38:11

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13791

Re: API pwg.images.add problems

Hi ImageAdmin and mistic,

pwg.images.addChunk + pwg.images.add is not planned for removal. It is used by pLoader (which is not maintained but still working fine), Lightroom (highly maintained) or iPhoto.

We just have "better" now:

1) pwg.images.addSimple is certainly the best solution if you have lightweight files to upload.

2) pwg.images.upload, added in Piwigo 2.7 for the web upload form, let you upload by chunks and I recommend it instead of pwg.images.addChunk + pwg.images.add

Now about your specific questions related to pwg.images.addChunk + pwg.images.add :

ImageAdmin wrote:

A. The chunkfiles appear on the server as decoded from the Base64 string back to its original form, as the bytesize correspond with the original image. But the file sizes vary whether I use line-endings or not in the Base64 encoding.

pwg.images.addChunk receives a base64 encoded string and decodes it before writing *.block file in upload/buffer.

I don't understand why you have "line endings" in your base64 string (you should not, just use your encode_base64 or equivalent function in your programming language).


ImageAdmin wrote:

B. The Piwigo web API explorer state under pwg.images.add:
Don't use "thumbnail_sum" and "high_sum", these parameters are here for backward compatibility. - whereas the document “pwg.images.add & pwg.images.addChunk” on the contrary promotes the use of  "thumbnail_sum" and optionally "high_sum".

Trust the API explorer (it is generated from Piwigo code, so it is always more up-to-date than any manually written documentation). I have just update [doc/wiki] pwg.images.add & pwg.images.addChunk to show the right way to use these methods with Piwigo 2.7.

What has changed since Piwigo 2.0? You don't need to upload thumbnail and high version. Just send the "file" and Piwigo will generate other sizes.

I also saw a bug in the send_chunks methods: previous version in the wiki was doing base64 and then splitting, but the right way is to do the opposite!


ImageAdmin wrote:

C. The Piwigo web API explorer and the document “pwg.images.add & pwg.images.addChunk” disagree on which parameters are available:
- original_filename, check_uniqueness and image_id in the API explorer is not mentioned in the document, whereas file_sum in the document is not mentioned in the API explorer.

I modified the documentation consequently, thank you for showing these coherence issues.

ImageAdmin wrote:

1. Should the md5sum of a chunkfile reflect the image it is chunking (eg. thumb or file), or should I use the same md5sum for all chunkfiles regardless of filetype? The latter must be the consequence if "thumbnail_sum" and "high_sum" should not be used. What md5sum should then be used?

You only have to give one filetype (ie "file"). The original_md5sum is used to have a unique identifier and to check for uniqueness if you set check_uniqueness to "true".

So, use the hexadecimal md5sum of the original file.

ImageAdmin wrote:

2. Which parameters are minimum necessary with pwg.images.add? And what does check_uniqueness and image_id do? I really want to upload both high, file and thumb for each image.

I think the updated documentation gives enough details:

doc page wrote:

(optional) check_uniqueness : check if file already exists (based on filename or md5sum, see $conf['uniqueness_mode'] in include/config_default.inc.php)
(optional) image_id : give an image_id if you want to update an existing photo

... and no need to upload "high", totally useless with Piwigo 2.7.

Offline

 

#6 2015-01-28 00:15:37

ImageAdmin
Member
2014-12-24
3

Re: API pwg.images.add problems

Dear plg,

thank you SO MUCH for taking my questions seriously! With yours very concrete answers and the updated documentation, I managed to put in place the last pieces and succeed. Very encouraging indeed!!

Offline

 

#7 2015-06-16 11:53:40

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13791

Re: API pwg.images.add problems

FYI I just created a new page in the wiki to give details about pwg.images.upload http://piwigo.org/doc/doku.php?id=dev:w … ges.upload

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact