Raymond Geerts Posted January 6, 2016 Share Posted January 6, 2016 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 DataFilename 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? Link to comment Share on other sites More sharing options...
LostKobrakai Posted January 6, 2016 Share Posted January 6, 2016 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. 2 Link to comment Share on other sites More sharing options...
Raymond Geerts Posted January 6, 2016 Author Share Posted January 6, 2016 @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. 1 Link to comment Share on other sites More sharing options...
horst Posted January 6, 2016 Share Posted January 6, 2016 $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)); 8 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted January 6, 2016 Share Posted January 6, 2016 @Horst... wow.... 1 Link to comment Share on other sites More sharing options...
Raymond Geerts Posted January 6, 2016 Author Share Posted January 6, 2016 @Horst thanks for the working example. Saves me from typing 2 Link to comment Share on other sites More sharing options...
horst Posted January 6, 2016 Share Posted January 6, 2016 @Horst... wow.... I found wireTempDir myself a few days ago, so memory fingerprint was fresh. 1 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted January 6, 2016 Share Posted January 6, 2016 Found it via pw3.0 (in seperate class) Looked for it in 2.7 and mentioned to Raymond. 2 Link to comment Share on other sites More sharing options...
Raymond Geerts Posted January 6, 2016 Author Share Posted January 6, 2016 Note: $tmpDir = wireTempDir('someName'); Should be: $tmpDir = new WireTempDir('someName'); 3 Link to comment Share on other sites More sharing options...
horst Posted January 6, 2016 Share Posted January 6, 2016 Thanks Raymond. Have updated it in the code example above. 1 Link to comment Share on other sites More sharing options...
bernhard Posted March 2, 2016 Share Posted March 2, 2016 there are still some wrong wireTempDir that shoud be WireTempDir Link to comment Share on other sites More sharing options...
LostKobrakai Posted March 2, 2016 Share Posted March 2, 2016 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. Link to comment Share on other sites More sharing options...
bernhard Posted March 2, 2016 Share Posted March 2, 2016 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) Link to comment Share on other sites More sharing options...
LostKobrakai Posted March 2, 2016 Share Posted March 2, 2016 Ah. It's probably because of the namespacing in PW 3.0 http://code.runnable.com/Vtcay97VO6lCfjAD/case-sensitive-class-test-for-php Edit: OK, strangely the published snippet doesn't throw. So I'm not sure about it. Link to comment Share on other sites More sharing options...
bernhard Posted March 2, 2016 Share Posted March 2, 2016 i got this error on 2.7.2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now