Jump to content

Recommended Posts

Posted

I'm working on a XML RPC api to communicate between WoodWing Enterprise and a ProcessWire site.

One of the method calls i'm building is pw.uploadPWFile which has to upload files, it does this by posting a XML RPC call to this method sending the following parameters as payload:

  • Page ID
  • Username
  • Password
  • Data
    • Filename
    • MIME Type
    • Bits (base64)

I could not find any example on how to upload a file from base64 binary posted data, and how to assign this file to a field.

Are there any examples available or can sombody point me in the right direction?

Posted

Save the base64 data as decoded file to a temporary place (e.g. /assets/cache/) and then just add it to the file field and it will be copied to the correct path.

  • Like 2
Posted

@LostKobrakai thanks for the tip. Martijn also mentioned this method.

To be sure the temp file gets removed properly after a certain amount of time, i will use the WireTempDir class to create a tmp folder which will be removed automaticly after a X amount of time.

Create the file (from base64) in there with fwrite and assign the file path of the tmp file to my image field.

  • Like 1
Posted
$tmpDir = new WireTempDir('someName');
// add files
$fileBasename = 'basename.ext';
$filename = $tmpDir->get() . $fileBasename;
file_put_contents($filename, base64_decode($b64Data));
$page->files->add($filename);
// repeat for all files ...

// optionally, at the end call
$tmpDir->removeAll();

EDIT: Ah, you already know / found WireTempdir() :)

EDIT2: If one use WireTempDir for very timeconsuming tasks, one optionally can define a maxAge for it, different than the default 120 seconds:

$tmpDir = new WireTempDir('someName', array('maxAge' => 300));
  • Like 8
  • 1 month later...
Posted

Actually php isn't case sensitive in terms of class names, therefore both should work. But still WireTempDir feels to be less prone to errors coming up.

Posted

ok maybe thats related to tracydebugger?

ErrorException: Class 'wireTempDir' not found in /var/www/...module:65
Stack trace:
#0 [internal function]: Tracy\Debugger::shutdownHandler()
#1 {main}
(stored in /var/www/.../site/assets/logs/tracy/exception--2016-03-02--17-39--0979d2c325.html)

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...