Sorry if this is an issue for the REST module rather than file_entity, but I could not upload files at all using the REST API until I downloaded and enabled this module.

The issue I'm experiencing is that while I can create new file entities by POSTing a base64 encoded file, the filemime setting is ignored and is always set to "application/octet-stream":

curl --include --request POST 
--header 'Content-type: application/hal+json' 
http://site.dev/entity/file?_format=hal+json 
--data-binary
{
  "_links": {
    "type": {
      "href": "http://site.dev/rest/type/file/image"
    }
  },
  "filename": [{"value": "file.png"}],
  "filemime": [{"value": "image/png"}],
  "type": [{"target_id": "image"}],
  "data": [{
    "value": "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAMAAACBVGfHAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAkUExURUxpcSOq4SOq4SOq4SOq4SOq4SOq4SOq4SOq4SOq4SOq4SOq4U0m8UcAAAAMdFJOUwD/EvAm2qhTPMRrkl4CMYAAAAE1SURBVCjPXZG/S8NQEMePR7Ehnb48khC7BEFFnYJD6/aWOLilVBy6WBVc648/oCii1KlFKDrFwV2tqH+edy9Rk7zh8e7Dfe++944oP5dUO59RDQyPqrFK/WqKCzxUwA30oJyymervlVK8PsVBOd85hh6pyflfhwXg024cjguwBqCjhsCsSOAn+k4MBGpUWAB6Tb6W1VxAgv+MfcPgWUBgazjxoYwlQLrsmBa6MhbH3hep2yu6QJuowWL9Yfs1U4QRSbWOjRts0DMCdEbqjl8s1kYkPqmX7YGRfgy4aJe2IB+0wZJI2s7ojEGbWtJejL1aL55h+wGDVWTWix47+cAug6kAycjs+LkkjFzku0h6dC3D01KxCmdOLrt7pyQ0+Z/tRXT/eEr0dvL7y6zkrbhPtYVPrOAHKZQ53IyepQMAAAAASUVORK5CYII="
  }]
}

Response:

{
   "fid":[
      {
         "value":"10"
      }
   ],
   "uuid":[
      {
         "value":"d57fc72e-c527-4c70-a4ad-820050506a5d"
      }
   ],
   "langcode":[
      {
         "value":"en"
      }
   ],
   "uid":[

   ],
   "filename":[
      {
         "value":"image.png"
      }
   ],
   "uri":[
      {
         "value":"public:\/\/file6GF0Fz"
      }
   ],
   "filemime":[
      {
         "value":"application\/octet-stream"
      }
   ],
   "filesize":[
      {
         "value":488
      }
   ],
   "status":[
      {
         "value":false
      }
   ],
   "created":[
      {
         "value":1466642149
      }
   ],
   "changed":[
      {
         "value":1466642149
      }
   ],
   "type":[
      {
         "target_id":"image",
         "target_type":"file_type",
         "target_uuid":"c4ab5ab7-b9ad-4f7e-946d-17d8c397b50d"
      }
   ],
   "field_image_alt_text":[

   ],
   "field_image_title_text":[

   ]
}

Comments

scott.whittaker created an issue.

scott.whittaker’s picture

For that matter it also appears that it does not use the supplied filename either and creates a file with a generated name and no file extension.

scott.whittaker’s picture

Interesting, I discovered that if I manually set the URI:
"uri":[{"value":"public://image.png"}],
then it uses that to name the file and sets the mimetype correctly.

So that's good, though it means that the application that makes the call to the API needs to know about the folder structure of the Drupal filesystem and I guess there's no way to dynamically use file storage path settings for the field of the entity to which the file will eventually be attached...

scott.whittaker’s picture

One more issue, which I will probably raise as a separate issue if I don't find an answer for it, is that the files are created with a temporary status which means that the file ID cannot be assigned to any content. So the image file entity looks perfect, but it can't actually be used for anything, and presumably will be cleaned up by the system at some point. So this is another major showstopper.

ronin17’s picture

Thanks for the info on setting the uri, and the patch for the temp file issue, that has saved me a lot of troubleshooting.

Just curious if you had any additional patches or tips you'd recommend for someone who is also working with D8 and REST?

bas.bakker’s picture

Hi @ronin17, where did you find the patch?

@scott.whittaker thanks for the hint on setting the uri! Saved my day :)

ronin17’s picture

@bas.bakker - Sorry, should have linked that issue, you can find it here: Issue #2756127