0

I am working on an app that allows customers to upload images, video, (even gif) into my app. Once the case is processed on my app, I want to place those media files into Salesforce. I have a case record that I would this attached to.

I see multiple records can be added in Rest here, and that files can be added to notes and attachments. Can I upload multiple notes and attachments in a single rest call?

2

Yes, there are a few ways to upload files. You can use the API you referenced in your question (the "create new records" API), and you can also upload using a multipart upload.

For the first type of upload, the file is uploaded as a base64-encoded data. It would look like this:

POST /services/data/v43.0/composite/tree/Attachment
Content-Type: application/json

{ "records": 
  [ { "attributes": { "type": "Attachment", "referenceId": "rec1" },
    "contentType": "text/plain",
    "name": "hello-world.txt",
    "body": "SGVsbG8gd29ybGQ=",
    "parentId": "001100000123456" 
    } 
  ] 
}

This method is limited to about 37MB uploads, however, because this API call is limited to 50MB, and Base64-encoding increases a file's size by 33% during transfer.

Alternatively, you can use the composite multipart API to deal with larger files.

POST /services/data/v42.0/composite/sobjects/
Content-Type: multipart/form-data; boundary="boundary_string"

--boundary_string
Content-Disposition: form-data; name="collection"
Content-Type: application/json

{
    "allOrNone" : false,
    "records" :
    [
        {
            "attributes" :
            {
                "type" : "Attachment",
                "binaryPartName": "binaryPart1",
                "binaryPartNameAlias": "Body"
            },
            "Description" : "Marketing Brochure",
            "FolderId" : "some-parent-id",
            "Name" : "Brochure",
            "Type" : "pdf"
        },
        {
            "attributes" :
            {
                "type" : "Attachment",
                "binaryPartName": "binaryPart2",
                "binaryPartNameAlias": "Body"
            },
            "Description" : "Pricing Overview",
            "ParentId" : "some-record-id",
            "Name" : "Pricing",
            "Type" : "pdf"
        }
    ]
}

--boundary_string
Content-Disposition: form-data; name="binaryPart1"; filename="Brochure.pdf"
Content-Type: application/pdf

Binary data goes here.

--boundary_string
Content-Disposition: form-data; name="binaryPart2"; filename="Pricing.pdf"
Content-Type: application/pdf

Binary data goes here.

--boundary_string--

NOTE: This is just a slightly modified version of what's in the documentation. Feel free to read the documentation for any further questions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.