Jump to content

Uploading images via API 'Pageimages: Removed' issue


Recommended Posts

Posted

Folks. Hope everyone is well.

I'm attempting to move some Tumblr content to PW using the API. I have the below, which seems to work fine, except even though the images are uploaded (they appear in the appropriate assets/files/** folder), when I go to edit the page the images are all removed with the message Pageimages: Removed 'images' temp file(s) for page...

Any thoughts where I'm going wrong?

$url = $config->paths->templates . "tumblr/posts/posts.xml";
$xml = simplexml_load_file($url);

$i = 0;
foreach ($xml->posts->post as $post) {

	bdb($post);
	$attributes = $post->attributes();

	$date = $sanitizer->date($attributes["unix-timestamp"]);

	$text = str_replace('</p>', '', $post->{"photo-caption"});
	$text = explode('<p>', $text);

	$title = $sanitizer->text($text[2]);
	$description = array_slice($text, 3);

	$p = new Page();
	$p->template = "blogSingle";
	$p->parent = "/blog/";

	$p->of(false);

	$p->title = $title;
	$p->date = $date;

	$descriptionString = '';
	foreach ($description as $d) {
		$descriptionString .= "<p>" . $d . "</p>";
	}
	$p->textarea = $descriptionString;

	$p->save();

	if (count($post->photoset) > 0) {
		foreach ($post->{"photoset"}->{"photo"} as $images) {
			$image = $sanitizer->url($images->{"photo-url"}[0]);
			$p->images->add($image);
			$p->save();
		}
	} else {
		$image = $sanitizer->url($post->{"photo-url"}[0]);
		$p->images->add($image);
		$p->save();
	}

	$p->save();

	$i++;
	if ($i == 2) break;

}

 

Posted

@a-ok try adding $p->of(false); before adding the image. You've included output formatting off above when creating the page, but then the page is saved which automatically turns it on again.

  • Like 1
Posted
25 minutes ago, psy said:

@a-ok try adding $p->of(false); before adding the image. You've included output formatting off above when creating the page, but then the page is saved which automatically turns it on again.

@psy Many thanks for the help. It doesn't seem to make a difference unfortunately. Hmm...

Posted

If I use TracyDebugger and run this:

$page->of(false);
$page->images->add("https://66.media.tumblr.com/f4958343844738fa507dc53d6493c988/tumblr_pszpc6YZF51uoauero1_1280.png");
$page->save();

It works fine ?

  • Like 1
Posted
13 hours ago, a-ok said:

$p->images->add($image);

What happens if you replace this with the hardcoded url in the tracy example?

Just replace block after block with working snippets and you'll find the problem or can at least narrow down where it is and tell us more about it ? 

Posted
1 hour ago, bernhard said:

What happens if you replace this with the hardcoded url in the tracy example?

Just replace block after block with working snippets and you'll find the problem or can at least narrow down where it is and tell us more about it ? 

Thanks, @bernhard – I did this and it added the images (visible in the folders within assets) but upon visiting it in the backend they were removed with the same message 'Pageimages: Removed 'images' temp file(s) for..'

Posted

I've decided to disable it, run the process, then re-enable it.

As there is quite a lot of pages to create (200) with multiple images per page is there a best practice/method you would suggest in order to run this?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...