Skip to main content

I have a case Where I need to accept files as multipart/form-data. Which I will link with provided EntityId. Now my Issue is Every endpoint exposed through normal way has some restriction like it doesn't accept multipart/form-data. How can I achieve this.

3 respuestas
  1. 7 jun 2024, 09:54

    Salesforce already exposes a standard endpoint for accepting multipart/formdata

    Assuming the case already exists in your salesforce org (id= 5009O00000DKLC5QAP)

     

    More info : https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_insert_update_blob.htm

     

    Sample multipart request below:

    URL =  /services/data/v58.0/composite/sobjects 

    HEADERS = Content-Type:multipart/form-data; boundary="boundary_string"

     

    BODY = 

    --boundary_string

    Content-Disposition: form-data; name="collection"

    Content-Type: application/json

    {

        "allOrNone" : false,

        "records" :

        [

            {

                "attributes" :

                {

                    "type" : "ContentVersion",

                    "binaryPartName": "binaryPart1",

                    "binaryPartNameAlias": "VersionData"

                },

                "PathOnClient": "penta_multipart_File_1.png", //name+extension of the file

                "FirstPublishLocationId": "5009O00000DKLC5QAP", 

                "Title": " penta_multipart_File_1.png" 

            },

            {

                "attributes" :

                {

                    "type" : "ContentVersion",

                    "binaryPartName": "binaryPart2",

                    "binaryPartNameAlias": "VersionData"

                },

                "PathOnClient": "penta_multipart_File_2.png", 

                "FirstPublishLocationId": "5009O00000DKLC5QAP", /

                "Title": "penta_multipart_File_2.png" 

            },

            {

                "attributes" :

                {

                    "type" : "ContentVersion",

                    "binaryPartName": "binaryPart3",

                    "binaryPartNameAlias": "VersionData"

                },

                "PathOnClient": " penta_multipart_File_3.png", 

                "FirstPublishLocationId": "5009O00000DKLC5QAP", 

                "Title": " penta_multipart_File_3.png" 

            }

        ]

    }

    --boundary_string

    Content-Disposition: form-data; name="binaryPart1"; filename="invoice_january.pdf"

    Content-Type: application/pdf

    Binary data goes here. for File 01

    --boundary_string

    Content-Disposition: form-data; name="binaryPart2"; filename=" invoice_february.pdf"

    Content-Type: application/pdf

    Binary data goes here. for File 02

     

    --boundary_string

    Content-Disposition: form-data; name="binaryPart3"; filename=" invoice_march.pdf"

    Content-Type: application/pdf

    Binary data goes here. for File 03

    --boundary_string-- 

0/9000