I have been successful in using feeds for importing multiple images into an image field.
If anyone coming from Google is reading this, the key is to prepare your CSV like this (note the commas and semicolons):
"uid";"image_url";"title";"alt"
12345;url1,url2,url3,url4;title,title,title,title;alt,alt,alt,alt
and use feeds tamper to apply "explode" on image_url, title and alt
but this is not what I want to ask here
I am now faced with the task of importing thousands of images which are currently stored in a file structure similar to this:
/gallery/UNIQUE_ID/*filename*
and I need them like this:
UNIQUEID1;*filename*,*filename*,*filename*,*filename*,*filename*,*filename**filename*,*filename*
UNIQUEID2;*filename*,*filename*,*filename*,*filename*,*filename*
...
I can easily get the list of files with their full path using for example dir /b /s > file.txt in CMD (windows) or similar on unix, but there is lots of cleanup to do. like... a bit too much
so does anyone know a way to do it quicker?
if that's impossible, I would like to know if it's possible to *append* images to existing content in an imagefield ?
using excel, I can easily produce something like the following, but so far my tests to append new images to an image field have been unsuccessful. Is there a way to do this?
UNIQUEID1;*filename*
UNIQUEID1;*filename*
UNIQUEID1;*filename*
UNIQUEID1;*filename*
UNIQUEID1;*filename*
UNIQUEID1;*filename*
UNIQUEID2;*filename*
UNIQUEID2;*filename*
UNIQUEID2;*filename*
UNIQUEID2;*filename*
UNIQUEID2;*filename*
Many thanks for any help or ideas
Comments
Comment #2
megachrizThe 'append value' feature has been requested a lot in the past, but it is something Feeds cannot do at the moment without custom code (or hacking the code).
What Feeds does for each import row, is first emptying each field being mapped to and then set the values for them. This prevents having duplicate values and allows users to import empty values.
There are a few challenges to overcome in order to support this, all related to updating existing entities.
Challenges
Say you're importing fruits on a multivalue field and on import 1 these are apple, banana and orange. In the append values workflow you would get three fruits imported in one field.
You change the source: you remove the orange and replace it with a lemon. Now on import 2 you'll get: apple, banana, orange, apple, banana, lemon. That's because apple and banana are still in the source file and get appended again.
In the append values workflow this would be harder to do. As you saw in the previous example, the orange remained on the field, despite that it no longer appeared in the source file.
If you would have the append values workflow for every field, then on subsequent imports you'll get errors for fields that have a limit on how many values are allowed. For example: the node title field can only hold one value.
I can imagine there might be more things to overcome, but these above where the ones I could think about right now.
I've came up with some ideas to overcome these challenges but these may introduce other challenges:
Before saving, Feeds could make sure that on multivalue fields every value may only appear once. But this would limit use cases where you actually want to have the same value appear more than once on a list. So I think this is a bad idea.
This idea might come a lot closer to a solution. When during the same import, Feeds comes across an entity a second time, it doesn't empty the fields again.
Challenge in these are the following:
This could fix the issue for fields that can only contain 1 value. Maybe autohide the option for single value fields.
For D7, a module called "Feeds empty" was created to start exploring the append values workflow. I'm not sure how well it worked for D7, but it has no D8 port that I know of.
Possible workaround
In
EntityProcessorBase::map(), the methodclearTarget()gets called:As you see in this code, clearing targets is already skipped for the feeds_item field target. So a quick fix for you for now could be to add a second condition in which clearing values is skipped. For example, if your field is called 'field_image':
I haven't tested if this would work. And it can happen you run in one of the issues mentioned above (like getting duplicates for example).
I hope this helps you further.
Comment #3
drupaldope commentedThank you for your reply MegaChriz
I feel starting to tinker with feeds behaviors opens the door to too many unpredictible results.
In cases of site migrations, I guess most people are in the same situation as me, i.e. all pictures will have t be imported only once, so finding an elegant way to generate the CSV file might be what will help most users.
If anyone has an idea or code snippet in VBS or PHP to generate the CSV file from a flat text file containing picture URLs that include the GUID, please post here!
Thank you
I will try to write something myself, but don't hold your breath ;-)
Comment #4
drupaldope commentedNailed it!
here is a piece of PHP code that will produce the desired CSV list, adapt for your needs
Comment #5
Qadees commented@Manarak,
Sorry to ask, how do I apply this PHP code?
Comment #6
drupaldope commented@Qadees
I run wampserver on my Windows machine, so I have local PHP.
I put all the directories and files into a local wampserver directory, and the PHP script at the directory root, and then navigate the browser to it.
feel free to ask for more details if I was unclear
wampserver_website_webroot / galleries / unique_ID / files
wampserver_website_webroot / PHPscript
Comment #7
Qadees commentedThank fo reply Manarak,
Does that mean you did not use feed module to achieved the append function?
If you use feed module, do you hack the code that handles the Import?
Comment #8
drupaldope commented@Qadees
yes, I use the feeds module, and no, I don't hack the code.
the code I provided here just helps me putting the filenames into the correct format, so that I can make the CSV file for feeds to import multiple images into one image field.
Comment #9
igorgoncalves commentedJust a update about this issue, that @drupaldope comment helps me solve on my case.
I have a csv like:
code_id,member_id
123,0001
124,0001
123,0002
223,0002
where code_id its a field of my taxonomy and member_id also a custom id field from our user.
so, i had to handle the csv as it come, do all the referals from code and member ids to their respective entities and save all terms to the user.
The steps was to: