Skip to content

Commit

Permalink
Update docs about file/image field serialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasgraf committed May 27, 2016
1 parent 1d49315 commit 6e93384
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions docs/source/serialization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,44 @@ will be serialized to
"encoding": "utf-8"
}
File Fields
-----------
File / Image Fields
-------------------

Download (serialization)
^^^^^^^^^^^^^^^^^^^^^^^^

For download, the file field will simply be serialized to a string that contains the download URL for the file.
For download, a file field will be serialized to a mapping that contains the
file's most basic metadata, and a hyperlink that the client can follow to
download the file:

.. code:: json
{
"...": "",
"@type": "File",
"title": "My file",
"file": "http://localhost:55001/plone/file/@@download/file"
"file": {
"content-type": "application/pdf",
"download": "http://localhost:55001/plone/file/@@download/file",
"filename": "file.pdf",
"size": 74429
}
}
That URL points to the regular Plone download view.
That URL in the ``download`` property points to the regular Plone download
view. The client can send a ``GET`` request to that URL with an ``Accept``
header containing the MIME type indicated in the ``content-type`` property,
and will get a response containing the file.

This means that when accessing that URL, your request won't be handled by the API but a regular Plone browser view.
Therefore you must **not** send the ``Accept: application/json`` header in this case.
Image fields are serialized in the same way, except that their serialization
contains an additional property ``scales`` that contains a mapping with
hyperlinks to the respective image scale URL.

Upload (deserialization)
^^^^^^^^^^^^^^^^^^^^^^^^

For a field of type ``Named[Blob]File`` (Dexterity) or ``FileField`` (Archetypes), represent the field content as a dictionary with these four keys:
For file or image fields, the client must provide the file's data as a mapping
containg the file data and some additional metadata:

- ``data`` - the base64 encoded contents of the file
- ``encoding`` - the encoding you used to encode the data, so usually `base64`
Expand Down

0 comments on commit 6e93384

Please sign in to comment.