Hi, I'm trying to create a new file by doing a PUT call to /rest/file/ (rest is my rest endpoint) and I'm getting the following exception:

<?xml version="1.0" encoding="utf-8"?>
<result>
<xdebug_message>( ! ) UuidEntityException: Trying to save a File entity with empty or invalid UUID. in sites/all/modules/custom/uuid/uuid.entity.inc on line 239 
Call Stack #TimeMemoryFunctionLocation 
10.0917333388{main}( )../index.php:0 
20.276323767612menu_execute_active_handler( ???, ??? )../index.php:21 
30.277023768656call_user_func_array ( ???, ??? )../menu.inc:516 
40.277023769036services_endpoint_callback( ???, ???, ??? )../menu.inc:516 
50.289525406148call_user_func ( ??? )../services.module:202 
60.289525406148rest_server_server( )../services.module:202 
70.291525580148RESTServer->handle( ???, ??? )../rest_server.module:34 
80.308126480064services_controller_execute( ???, ???, ??? )../RESTServer.inc:150 
90.309226482060call_user_func_array ( ???, ??? )../services.runtime.inc:144 
100.309226482376_uuid_services_entity_access( ???, ??? )../services.runtime.inc:144 110.311826611404entity_make_entity_local( ???, ??? )../uuid_services.module:182 </xdebug_message>
</result>

When I'm debugging this I see that $entity = entity_create($entity_type, $args[2]); on uuid_Services.module returns FALSE since if (isset($info['creation callback'])) { fails on entity.module for entities of type file.

Will report back if I find anything else but I'd love to hear from someone that is more up to speed with uuid_services and knows why we can't use entity_create with new files?

Thanks!

Possible solutions:

#1778484: UUID Services for file should not use the update method. After this issue gets resolved the problem should be fixed. As a temporary solution, the patch in this issue #1741028: Support creation for files solves the problem.

Comments

lucascaro’s picture

For the record, I'm doing a REST call directly to my services endpoint:

URL: http://localhost/site/rest/file/27cfd11d-1007-6684-91f8-9a7a521ce3aa

METHOD: PUT

Content-Type: application/json

BODY:

{
"file":"/9j/4A[...]FAH/2Q==",
"filename": "file.jpg",
"uuid": "27cfd11d-1007-6684-91f8-9a7a521ce3aa"
}
lucascaro’s picture

Assigned: Unassigned » lucascaro
lucascaro’s picture

It seems that this problem is directly related to #1741028: Support creation for files so I'll work on that one first. Also, we need to review _uuid_services_entity_access since access for files is somewhat different (see #1136356-5: Fix file access) they only check for $op == 'view' so we're out of luck for creating, updating, or deleting files (we're probably going to need to add a wrapper for validating files like the services module does, or even use _file_resource_access after loading the file by uuid.

As a side note, see the comment above _file_resource_definition()

/**
 * THERE SHOULD BE NO UPDATE!!!
 * Drupal doesn't allow updating or replacing a file in the files table.
 * If you need to, create a new file and remove the old file.
 */

So I guess we have a conflict here since the uuid_services module uses update by default. we might want to make a special case for files and manage them with create, retrieve and delete just like the services module does, in which case files are created using file_save_data (see _file_resource_create()) and the permissions are checked with

user_access('save file information')
lucascaro’s picture

fmizzell’s picture

There is still some debate going on in #1778484: UUID Services for file should not use the update method., so using #1741028: Support creation for files as a temporary solution works to allow files to be deployed.

fmizzell’s picture

Issue summary: View changes
fmizzell’s picture

Issue summary: View changes