Can someone please help me figure out how to use node.save to save a node of a content type containing a CCK ImageField ? Here is the setup:
Flex 3, PHP, Drupal 6, Services (all sub-modules enabled), DrupalSite Flex Framework.
Drupal:
I've got a content type called "Photo" which contains the following fields: Title, Photo (ImageField), and Taxonomy.
Flex:
Currently, I have DrupalSite working (I can retrieve all nodes of type 'Photo'). My app does a lot more, but in a nutshell, I have a photo upload that is currently dumping the user's photo in to a temp directory on the server. I need to save this image file to a new node (Photo).
I have read that you can just upload an image into a temp directory Drupal can see, then node.save will take care of everything for you... it can't be this easy. I figured I'd move the file where it belongs using Flex/PHP, then manually write the photo field data as parameters.
Thank you kindly!
Oh, FYI: here is what node.get gives me.
stdClass Object
(
[nid] => 1
[type] => photo
[language] =>
[uid] => 2
[status] => 1
[created] => 1236693429
[changed] => 1236695418
[comment] => 2
[promote] => 0
[moderate] => 0
[sticky] => 0
[tnid] => 0
[translate] => 0
[vid] => 1
[revision_uid] => 2
[title] => Moon
[body] =>
[teaser] =>
[log] =>
[revision_timestamp] => 1236695418
[format] => 0
[name] => jdoe
[picture] =>
[data] => a:1:{s:13:"form_build_id";s:37:"form-191428de76d3118c3aca581cd710a182";}
[path] => photo/1
[field_photo] => Array
(
[0] => Array
(
[fid] => 1
[list] => 1
[data] => Array
(
[description] => Man on the moon
)
[uid] => 2
[filename] => astronaut.jpg
[filepath] => sites/default/files/photos/astronaut.jpg
[filemime] => image/jpeg
[filesize] => 50031
[status] => 1
[timestamp] => 1236693425
)
)
[last_comment_timestamp] => 1236693429
[last_comment_name] =>
[comment_count] => 0
[taxonomy] => Array
(
[1] => stdClass Object
(
[tid] => 1
[vid] => 1
[name] => moon
[description] =>
[weight] => 0
)
)
[body_value] =>
)
Comments
irc message
Someone in #drupal-support posted this:
one service call will have to go out to save the image, that one should return the location, then another service call can go out to attach the result to the node
A Solution!
Using the patch at http://drupal.org/node/376226 I have been able to solve this problem. There are still some minor issues like getting the file size into the database.
Please read the initial post to see specifics about the environment. The code blocks weren't showing comments properly... so I've pastebin'd the entries (using the forever setting).
Addition to DrupalSite.as (added around line 340, before the getNode function is declared)
http://pastebin.com/f379d5708
Addition to DrupalSite.as (added to the onData function, just after the node.save if statement)
http://pastebin.com/f2a2ffcdc
Flex/Actionscript
http://pastebin.com/f2b45ff79
If this saves someone even 20 minutes I'll be a happy camper :)
That's cool good job! I'm
That's cool good job! I'm looking to do something like this. I'd be interested to see what the FLex App is like.
step by step?
hi there..
i am trying to do exactly the same (flex to save 1 picture in a Photo content type)
I tried using DrupalSite but it didnt work for me and i found it too long to debug.
so i wrote a simply version that does the job too:
http://groups.drupal.org/node/21245
your posts were of huge help anyway! thank you so much
Thanks for your efforts
Thanks for your efforts jacopo3001 :) You are helping to shed light on this hard to find technique.
How did you make for your Services return your ImageField
Hello all,
i'm french, apologyze for my suck english.
I have done one View who return me one imageField. when i click on Preview buton of my view, i can see it.
Now i would like get this imageField from flex, so when i go to Services, i do view.get(myview'snam) and here is what its return to me for my ImageField :
Array
(
[0] => stdClass Object
(
[nid] => 265
[node_data_field_photo_widget_field_photo_widget_fid] => 305
[node_data_field_photo_widget_field_photo_widget_list] => 1
[node_data_field_photo_widget_field_photo_widget_data] => a:3:{s:11:"description";s:0:"";s:3:"alt";s:0:"";s:5:"title";s:0:"";} My imageField here
[node_type] => photo_widget
[node_vid] => 275
[node_data_field_photo_widget_nid] => 265
[node_title] => titre
)
)
I would it return me as and array, like the first post on this page...
I dont know how to resolve this, plz help me ;)
Here is the solution
I have found the solution of my problème, its just was due to the Beta version i used for the Services Module.
http://drupal.org/files/issues/views-service.patch
voila ;)