0

I'm using drupal services module. I can upload files through web services but the problem is all created files has the same owner, that is, the user of the web services. I would like to change this user but I don't know how to do it.

I have been searching in drupal api functions (file.inc), but I haven't found a function to change this. How could I change the file's owner? Thanks.

  • Did you try just passing the uid along during the POST to ?q=my-endpoint/file.json? – tyler.frankenstein Jun 18 '15 at 15:26
  • Hi. Yes, I did it. But after I saw that nothing changed I inspected file_save_data function (file.inc) and I saw that this function has file->uid = $user->uid, that is, the user that is logged in. And then, it ignores the uid I pass. – briast Jun 19 '15 at 10:30
  • If file.inc has the user id hard coded in, then I think the only way around it is patching the file.inc module to listen for your POST user id. – tyler.frankenstein Jun 19 '15 at 19:52
  • Actually, check out hook_entity_presave(), you can probably use that to set the uid on the file to data available in the $_POST array: api.drupal.org/api/drupal/modules!system!system.api.php/… – tyler.frankenstein Jun 19 '15 at 19:54
0

I don't know of a module built to handle this, but you could build something easily enough to do it:

  • the DB table file_managed handles files, and includes a uid field which is the user ID of the file 'owner'

This could be modified in a custom module, but a MAJOR WARNING that I don't know what potential damage this could cause to other elements of the site, perhaps someone with more experience with the DB could add some advice in this regard

  • Yes. That is the quick way (It was I did), but I think It isn't the right way. As you said, this change directly on DB could cause problems with other elements. But I don't found a secure function to change it. – briast Jun 19 '15 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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