Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2019-10-07 16:03:23

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,760
Website

Re: smd_meta_image: create image/article metadata via IPTC on upload

etc wrote #319574:

The easiest way atm is to send some fileInputOrder value along with each file.

That’s perfect, good idea. The plugin can do this:

  1. If you set a pref to generate one article per file, it works as it does now.
  2. If you set that pref to generate one article per group of files, it will:
    1. Gather the filenames and create the images as it goes, as normal.
    2. Detect which one has fileInputOrder === 1 and call the article creation only for that image.

Easy! There’s not even any need to have a new callback in this case to trigger when they’re all done, as it can still do it as it receives each file.

Edit: Wait, yes it does need the callback as it needs to update the article to inject all the image IDs into the article_image field when they’re all uploaded, in the order they are presented to the <input/> box.

Last edited by Bloke (2019-10-07 16:04:37)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#12 2019-10-07 16:09:33

etc
Developer
Registered: 2010-11-11
Posts: 3,296
Website

Re: smd_meta_image: create image/article metadata via IPTC on upload

A new callback could be useful if you want to associate all batch-uploaded images to the new article, rearranging their ids as you need. Yep

Offline

#13 2019-10-07 16:18:43

etc
Developer
Registered: 2010-11-11
Posts: 3,296
Website

Re: smd_meta_image: create image/article metadata via IPTC on upload

Bloke wrote #319575:

Wait, yes it does need the callback as it needs to update the article to inject all the image IDs into the article_image field when they’re all uploaded, in the order they are presented to the <input/> box.

Done, but I dunno how to respect the order of all images. I fear that this “batch” callback is fired on each image upload. Needs testing/thinking…

Offline

#14 2019-10-07 16:26:58

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,760
Website

Re: smd_meta_image: create image/article metadata via IPTC on upload

Cool, thank you. I’ll run some tests as soon as I can.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#15 2019-10-07 19:28:37

etc
Developer
Registered: 2010-11-11
Posts: 3,296
Website

Re: smd_meta_image: create image/article metadata via IPTC on upload

Nope, this callback was useless, sorry, removed. We don’t upload all files in one array any more, so every file would trigger this callback with only its own id as data. The only way I can see atm is to subscribe to JS callbacks (uploadEnd is fired when all files have been uploaded) and issue an ajax request to the server. But that’s too cumbersome, we need something easier.

Offline

#16 2019-10-07 22:44:45

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,760
Website

Re: smd_meta_image: create image/article metadata via IPTC on upload

etc wrote #319580:

Nope, this callback was useless, sorry, removed.

I did take a cursory look at the code before you axed the callback, and that was my conclusion too. Shame, it would have been neat.

subscribe to JS callbacks (uploadEnd is fired when all files have been uploaded) and issue an ajax request to the server. But that’s too cumbersome, we need something easier.

Do we know how many files in total there are in the <input/> at the moment the upload button is clicked? If so, can we transmit that as another param? So we have fileInputOrder and, say, fileInputTotal sent with each file? That gives us (effectively) an image X of Y at the server so I can count up how many I’ve inserted and when it matches the total, I can trigger the article insertion using the metadata I stashed from the image designated as ‘1’.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#17 2019-10-08 07:24:05

etc
Developer
Registered: 2010-11-11
Posts: 3,296
Website

Re: smd_meta_image: create image/article metadata via IPTC on upload

Bloke wrote #319584:

I did take a cursory look at the code before you axed the callback, and that was my conclusion too. Shame, it would have been neat.

It would work in 4.5 where all files were sent in one request. But since we’ve been asked to overcome PHP max post size limits, now they are sent separately, in chunks if necessary. Only client-side JS knows now when everything is uploaded.

Do we know how many files in total there are in the <input/> at the moment the upload button is clicked? If so, can we transmit that as another param? So we have fileInputOrder and, say, fileInputTotal sent with each file? That gives us (effectively) an image X of Y at the server so I can count up how many I’ve inserted and when it matches the total, I can trigger the article insertion using the metadata I stashed from the image designated as ‘1’.

We could, but how would you know to which file “package” the uploaded files belong? I think you need to send a unique id with every package and insert image ids into corresponding article. It’s just not clear where to store this unique id: custom field, separate table?

Offline

#18 2019-10-08 08:48:36

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,760
Website

Re: smd_meta_image: create image/article metadata via IPTC on upload

etc wrote #319586:

how would you know to which file “package” the uploaded files belong?

Ah. Do the sequence numbers not begin at 1 for each set? I guess since everything’s ajax now it will only reset to 1 on page full refresh, right?

I just wondered if perhaps during a single “batch” or “package” of images, they could be numbered starting at 1 in the fileInputOrder param. Doesn’t matter what order they arrive, as each image calls file_insert() via the plugin anyway so I can test this ‘sequence number’ and stash the metadata for the one tagged as ‘1’ and increment a counter each time I see an image so I know how many have been inserted and can store the image IDs as I go.

Then, when I’ve seen them all (i.e. have inserted fileInputTotal images) I can trigger the article creation, stuff the metadata I stored from image ‘1’ into it, stuff the list of image IDs I collated into the article image field and commit.

If the sequence counter can be reset to ‘1’ again when uploadEnd fires, would that work? So the next batch of images uploaded start at 1 again.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#19 2019-10-08 08:55:27

etc
Developer
Registered: 2010-11-11
Posts: 3,296
Website

Re: smd_meta_image: create image/article metadata via IPTC on upload

Bloke wrote #319587:

If the sequence counter can be reset to ‘1’ again when uploadEnd fires, would that work? So the next batch of images uploaded start at 1 again.

Dunno what would happen if you start two long batch uploads at once, from different browser tabs. If they contain the same number of files, the server has no means to differentiate them.

Offline

#20 2019-10-08 10:22:57

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,760
Website

Re: smd_meta_image: create image/article metadata via IPTC on upload

etc wrote #319588:

Dunno what would happen if you start two long batch uploads at once, from different browser tabs. If they contain the same number of files, the server has no means to differentiate them.

True. Though I wouldn’t expect anyone who was using the plugin to work that way, it’s not outside the realm of possibility.

And I suppose different users could be doing it at the same time too huh. So unless we somehow knew which user the upload belonged to, we’re sunk.

Drat.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB