legacy-knowledge-base
公開されました Jun. 30, 2025

Upload attachments to custom objects Headless API

written-by

Daniel Carrillo Broeder

knowledge-article-header-disclaimer-how-to

knowledge-article-header-disclaimer

legacy-article

learn-legacy-article-disclaimer-text

Issue

  • Create a custom object having an attachment field.
  • Error 400 when trying to create an object using this field.
    {
    "status": "BAD_REQUEST",
    "title": "The value is invalid for object field \"attachmentField\""
    }

Environment

  • 2024.Q2+

Resolution

  • When using 2024.Q2 and 2024.Q3, the LPS-174455 Release Feature Flag must be enabled in order to be able to define base64 data while using object headless API (Control Panel→Instance Settings→Feature Flags→Release)
  • This feature is enabled by default starting from 2024.Q4.

Some minimal examples of JSONs that can be used with post<Object> API:

  1. Select an existing file from Document Library
    • Set the fileEntryId as attachmentField:
      {
      "externalReferenceCode": "EXAMPLE01",
      "attachmentField": 1234
      }
  2. Base64 file
    • The attachment must include the mandatory fields "name" and "fileBase64".
    • On Unix systems, the command base64 -w0 liferay_logo.png can be used to obtain the base64 string.
      {
      "externalReferenceCode": "EXAMPLE02",
      "attachmentField": {
      "name": "liferay_logo.png",
      "fileBase64": "iVBORw0KGgoAAAANSUhEUgAAAHAAAABwCAMAAADxPgR5AAAAulBMVEUAAAD///////////////////////////////////8TQZQaoOgLY86Mz/MnpukTQ5jx+f7w9fwRSKAYleERUKoSTaXC2PNvw/FTt+4NW8C34fip2/YMYMoOVrni8/zG5/k4gNcTcMUSW7E2rOsQVK/U7ftHitoSRZt+yfJhve8VesyFseYZm+ZmneBXk90XitgpdtQTX7ayzvBEsuwVgtMZbNEVZLvg6/nR4vajxO2Uuul1p+Oa1fVGgMbTiLVxAAAACXRSTlMAYPDQsDDgwEAh56snAAADQ0lEQVRo3u3bi3aaMBjAcZ22XQhyE4oCVVGs99pqL1u7vf9rraWzMQmafBFzznb4v8DvJHyxVLCWV2+is9es13ZdNJCWGhd/l/cNaepbPV8f3FMXP9bYQBprvG8o0lq91kRaa9aQ5iqwAiuwArkq8P8Ex1Er7HwWtuI+AgQHnXhmYabtNHIQqUywFxKNbhY75YNOiI9khb2SwcjCgjr9MsEplmjWKw0MMV6nw8Az8oJgmK4LyVZJ4HQ+tA0mezgvELfjEkD3N9EYs81PT3wq+LJKiMeVrQXbCgXdhWn6xrH4VYYngNf3ppkYx7PnnKgMLsz3bgxRQ1aM1UD3zvzIM4QF7Lb2VUB3kHuJIZHHiCMHAhKP7KhQXNLiFAYSj8yoIB/T9aBg7pFLKO6ZmVQguNp5iSHbI7NEEPjT3NWVBj3mKkLAl6cvMDOkS+lBhYC35leBPDjBVGMxSDaUNDHkm1NgSx683wMNQBkFdiRAfoFdCGhjKgHILZB8ziiejJ4k+INwZEhVDn9fEnzbBwMQ+CD6I1UT7ajpgcBANKY10Y6a9vnBVwo0zg+udIODfS+Bgb4KSC2wCwMfFED3FDBVOIfXp4CPOkH+s9Q5O5hRnoUUwOSES9gBgvBzOFnSQ3p28IG/3YeDHmBk2jSIlMBAeYEzSdClwUz+CjILjCVBRIM3wBElObLgQO1c+JjdUVnwTmlq7DYDRtLgKw364HtgcqOvcothdiETSorlQfQE31Of9SwHAK7Ac+otWfAXAoAbGkxswDcK5AoCQHZPM7CHIxi4IJjEf2wB73UQDHwxAYOaLTnP6gFB9MaIvuDfF+5IQEGXuYrJoU2dPBZ4MwQG0Ybd1OJJ9dsF3taBgOQDVXwY7RQXZI2RCugOhOKwDfYICBf9NS6sjwSgmujPizkrQmCQiCtWtHff5ZPVcfsJA/kvvKm63sfi0iU+0LZ38qOgDT2tyXPaxgebOmU8e3I3i7vbvMXrNULR6BA3ihCCg+KcllV49VpkeWAQTo4IBwABxaG1p4XUZsJB6UfPef2CyfzXH6tXYAUerQIrsALPn+5Xdq+0v5Ss+bXrS80vlqPvel+dR3W9Pw64zNen7ecPV5/L+wP1HO3zznjM/wAAAABJRU5ErkJggg=="
      }
  3. Empty optional attachments 
    • Do not include the attachmentField .
    • Setting an empty json {} will lead to error 400.
      {
      "externalReferenceCode": "EXAMPLE03"
      }
  4. Please refer to the additional information for more in-depth examples.

Additional Information

did-this-article-resolve-your-issue

legacy-knowledge-base