View Full Version : Bulk photo/gallery import script
incursio
04-13-2017, 03:49 PM
Hey guys, I am trying to import thousands of existing photos into VB5. The images exist in folders/subfolders on the server. Anyone have a basic script to programmatically create a new gallery folder for a user and import a photo into it? I can probably figure it out from there if I had a sample to look at. Thanks in advance!
--------------- Added 1492107744 at 1492107744 ---------------
A little more info as I keep trying to figure this out on my own - when I do this:
$response = $api->callApi('content_gallery', 'add', array('data' => $data, 'options' => $options));
I get the humanverify_missing error. It would seem to me that by using the API this would be disabled for the purpose of the request being made, but nevertheless ... so I disabled the Human Verification Manager in the admin panel, and now I get a "permission denied" error coming back from the API call.
noypiscripter
04-13-2017, 07:41 PM
How are you executing the api? You should be logged in to create gallery post unless you enable permissions for guests which I assume you don't want.
incursio
04-13-2017, 10:06 PM
Thanks! That helped me get past that issue. Now, I am getting this response when trying to add the image:
Array
(
[errors] => Array
(
[0] => Array
(
[0] => unexpected_error
[1] => Upload failed. PHP upload error: 0
)
)
)
My test code looks like this:
// This line does add the node for the album
$albumId = $api->callApi('content_gallery', 'add', array('data' => $data, 'options' => $options));
// Here, I get the info on a test file to try and add programatically
$fileName = '/var/www/mydomain.com/gw/photos/Architectural/wallpaper-1st-id-arch.png';
$fileParts = pathinfo($fileName);
$imageName = $fileParts['filename'];
// I don't want to lose the original file, so I copy it into a tempfile, to simulate uploading it
$tmpName = tempnam('/tmp', 'INC');
copy($fileName, '/tmp/' . $imageName);
rename('/tmp/' . $imageName, $tmpName);
$fileInfo = array();
$fileInfo['uploadFrom'] = 'profile';
$fileInfo['parentid'] = $albumId;
$fileInfo['tmp_name'] = $tmpName;
$fileInfo['name'] = $fileParts['basename'];
$fileInfo['size'] = filesize($fileName);
$fileInfo['type'] = 'image/png';
$photos = array($fileInfo);
// Upload the file and add it
$response = $api->callApi('content_attach', 'upload', array('photos' => $photos));
print_r($response); exit;
Any ideas?
--------------- Added 1492129123 at 1492129123 ---------------
Ok, I got past that problem. I needed to just pass 'file' => $fileInfo and do away with the $photos bit I was trying.
At any rate, it does "upload" the image, but now I need to somehow get it to show up in the gallery. I'm thinking I need to do something like this:
$response = $api->callApi('content_photo', 'add', ..... );
Just not sure what to pass to it.
--------------- Added 1492129263 at 1492129263 ---------------
Tried this, but to no avail:
$response = $api->callApi('content_photo', 'add', array($albumId, array('filedataid' => $response['filedataid'])));
I get this error:
Array
(
[errors] => Array
(
[0] => Array
(
[0] => invalid_data
)
)
)
--------------- Added 1492129526 at 1492129526 ---------------
Also, I noticed that in the vb_filedata table, that it had resized my test image (scaled it down). Is there some way to prevent that? These need to stay in their native 1920x1080 resolution. Thanks!
noypiscripter
04-14-2017, 06:32 PM
Also, I noticed that in the vb_filedata table, that it had resized my test image (scaled it down). Is there some way to prevent that? These need to stay in their native 1920x1080 resolution. Thanks!
In the Attachment Type Manager, you can configure the maximum width and height and filesize for each file extension.
incursio
04-17-2017, 11:52 AM
Any ideas on the actual call to "$api->callApi('content_photo' ...."? Is that the right call to use? If so, not sure what the arguments need to be.
I've also tried this, but to no avail:
// Upload the file and add it
$response = $api->callApi('content_attach', 'upload', array('file' => $fileInfo));
$data = array(
'parentId' => $albumId,
'filedataid' => $response['filedataid'],
);
$response = $api->callApi('content_photo', 'add', array('data' => $data));
incursio
04-22-2017, 08:42 PM
Anyone?
noypiscripter
04-23-2017, 01:45 AM
Take a look at the actionGallery() function in /includes/vb5/frontend/controller/createcontent.php. That's the function called when you submit a gallery content type post.
incursio
04-23-2017, 02:32 PM
Thanks, mate! I'll take a peek.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.