3

I have been having trouble getting a file to upload through http-post from my lisp application and I have noticed in all of the curl php examples I have found they have a like this:

$file = array(
  'filesize' => filesize($filename),
  'filename' => basename($filename),
  'file' => base64_encode(file_get_contents($filename)),
  'uid' => $logged_user->user->uid,
);

which includes the call to base64_encode, I am not doing this from my lisp application and I always get a response of 200 but the file is not uploaded. I am using Services 3.x and a RESt server.

Does Services require that file uploads are base64 encoded?

1 Answer 1

5

Short answer yes it does. There is a create raw method but unfortunately, it doesn't work very well b/c drupal 7s file handling is a joke.

Ive created a patch that will allow you to attach files to a node and it uses multipart form, but its a work in progress.

http://drupal.org/node/1484992

3
  • 1
    Okay that's very good to know, thank you so much. Also, would rest/file accept a multipart/form-data request normally? All the curl examples use application/x-www-form-urlencoded which seems wrong for uploading files. Is this due to the limitations of drupal you mentioned?
    – Mike2012
    Commented Mar 16, 2012 at 19:19
  • It supports multipart, but I'm not 100% sure for which methods, if its only certain ones, or it is all. Examples are usually done in curl because you can do curl in almost every major web aware language. Either way, if this is the answer you were looking for, please mark it as the answer :P Commented Mar 17, 2012 at 20:11
  • Compared to all the previous versions, D7's file handling is amazing ;)
    – drewish
    Commented Apr 30, 2012 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.