Hi everybody,
when sharing a file between multiple Drupal websites, it would be nice if they all share the same UUID.
In jsonapi_file it is possible to set the file UUID along with the file data. The following proposed request shows an example of how to achieve this when creating a file entity from binary data via JSON API requests.
Request:
POST /jsonapi/entity_type/bundle/file_field?id={uuid}
Content-Type: application/octet-stream
Content-Disposition: file; filename=image.jpg; resource-id={uuid}
Accept: application/vnd.api+json
// binary data
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | client-generated-id-3021155-8.patch | 10.99 KB | shenzhuxi |
| #6 | client-generated-id-3021155.patch | 5.48 KB | shenzhuxi |
Comments
Comment #2
wim leersThanks for reporting this!
Did some preparatory investigating:
d3bb4d69ea8a3948bd8f5e1c720d64a8cbeb09f7added explicit support for 409 responses when an entity already exists.Fileentity is created, it's in the core infrastructure that #2940383: [META] Unify file upload logic of REST and JSON:API is adding. Which means #2940383 would need to change to accommodate this, to allow a UUID to be specified and not just a filename.Comment #3
wim leersUpdating title to match that of #2934386: Accept client-generated IDs (UUIDs).
Comment #4
wim leersRelated: @gabesullice's comment at #2940383-19: [META] Unify file upload logic of REST and JSON:API.
Comment #5
wim leers#2958554: Allow creation of file entities from binary data via JSON API requests landed!
Comment #6
shenzhuxi commentedI would like to have this feature now, so I patched TemporaryJsonapiFileFieldUploader.php.
Comment #7
shenzhuxi commentedHere is the patch for Drupal core 8.7.x.
Comment #9
shenzhuxi commentedUpdated FileUploadTest.php to use the disposition-type in content-disposition following RFC 6266 (Support "attachment" and "file").
Comment #10
wim leers@shenzhuxi came to talk to me at Drupal Dev Days Cluj. I explained that:
restandjsonapi, to ensure that #2940383 doesn't become more complexI wish I had better news for @shenzhuxi — I understand that it's frustrating that so very few lines of additional code would solve his needs :/ We've all felt this pain of course 😩
And finally, the test coverage fixes in #9 (changing
Content-Disposition: filename=…toContent-Disposition: file; filename=…) is an independent bugfix that merits its own issue. But it also points to some missing validation. @shenzhuxi, please create a separate issue for that.