Ticket T1287247
Visible to All Users

Upload van mediadataobject via web api odata

created 11 days ago

Hi all,

I want to upload an image to a mediadataobject using the odata web api.

my request looks something like this

POST /odata/mediadataobject
payload is

Code
{  "MediaData" : "<base64 string>" }

Problem is I receive a bad request.
Am I doing something wrong?

thx Arjan

Answers approved by DevExpress Support

created 11 days ago (modified 11 days ago)

Hi, Arjan.

Please post the code for your all the queries and payloads for all the object types (including the container object type), because your current query looks incomplete. MediaDataObject is a regular persistent class with the MediaData property (a byte array). To initialize such reference properties, it is important to first create a MediaDataObject via POST at /odata/MediaDataObject and your JSON payload. Second, you must initialize YourContainerObjectType.YourMediaDataObjectReferenceProperty via POST or PATCH at /odata/YourContainerObjectType(yourEmployeeGuid) and this JSON payload:

JSON
{ "Photo": { "@odata.id": "/odata/MediaDataObject(yourNewMediaDataObjectGuid)" } }

or rather

JSON
"Photo": { "Oid": "yourNewMediaDataObjectGuid" }

You can find examples of working with reference properties here:

BTW, this procedure will be simplified (1 step instead of 2) in v25.1, where we support Deep Insert.

    Comments (2)

      hi Dennis,

      Yes that was my intention also, to first upload the image first and then use the returned "yourNewMediaDataObjectGuid" to update my other object.

      But this single POST already gives me a 400 (bad request) error

      (POST) /odata/mediadataobject

      JSON
      { "MediaData" : "<base64 string>" }
      Andrey K (DevExpress Support) 10 days ago

        Hello,

        I developed a simple example that uses a POST request to create a MediaDataObject object:

        Clipboard-File-1.png

        I have included the request body used for testing.

        Please test my example with the content I shared and inform me about its performance on your end.

        I look forward to your reply.

        Regards,
        Andrey

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.