0

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

I have been looking for the functions defined in the file.inc file, but I haven't found a function to change this. How could I change the file's owner?

4
  • Did you try just passing the uid along during the POST to ?q=my-endpoint/file.json? Jun 18, 2015 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, 2015 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. Jun 19, 2015 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/… Jun 19, 2015 at 19:54

1 Answer 1

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

1
  • 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 didn't find a secure function to change it.
    – briast
    Jun 19, 2015 at 10:34

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.