I am inserting ContentVersion (files) using the REST API endpoint /services/data/v55.0/sobjects/ContentVersion, which seems to be extremely slow. It is so slow, that it takes about a minute to upload 5MB files, and about 8 minutes for files that are 30MB. Is this normal? Am I doing something wrong?

Here is what my request looks like:

fetch('/services/data/v55.0/sobjects/ContentVersion', {
  method: 'POST',
  headers: {
    "Authorization": "Bearer " + sessionId,
    "Content-Type": "application/json",
    "Content-Disposition": "form-data; name=\"entity_content\";"
  body: JSON.stringify({
        PathOnClient: fileName,
        OwnerId: userId,
        FirstPublishLocationId: caseId,
        NetworkId: networkId,
        VersionData: base64data
}).then((res) => {
  let json = res.json();
  if (res.status >= 200 && res.status < 300) {
    return json;
  return json.then(Promise.reject.bind(Promise));

I have tried both with binary and base64 encoded data, which didn't make any difference. Any help would be greatly appreciated.

Edit 14.10.2022: I have changed the request to the documentation spec, however the results haven't changed. It is still extremely slow, and I have contacted SF Support. I will update this further if anything comes out of it. For those of you who may be interested, this answer is what I followed to achieve the correctly formatted request.

  • Is this against production or a sandbox? What's the network topology between the REST client and the Salesforce org (consider traceroute or similar)?
    – Phil W
    Oct 13, 2022 at 15:27
  • About 9 hops to the server from the client, nothing out of the ordinary when it comes to the latencies. It is equally slow for both sandbox and production.
    – Bartu
    Oct 13, 2022 at 15:35

1 Answer 1


You should be using multipart/form-data to upload the file. When you put it through entity_content, the entire thing has to be parsed as JSON instead of being passed directly to the database.

Example from the docs:

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

    "ContentDocumentId" : "069D00000000so2",
    "ReasonForChange" : "Marketing materials updated",
    "PathOnClient" : "Q1 Sales Brochure.pdf"

Content-Type: application/octet-stream
Content-Disposition: form-data; name="VersionData"; filename="Q1 Sales Brochure.pdf"

Binary data goes here.



  • Hey, thanks for you answer. I have tried to do it this way, however I am getting 400 bad request response with "You have sent us an Illegal URL or an improperly formatted request." sent back. Also, what is the binary data supposed to be? Is base64 string correct?
    – Bartu
    Oct 13, 2022 at 15:46
  • @Bartu Follow the documentation closely. You'll have to include the appropriate headers, including the boundary string. I haven't tried to do this with fetch previously, but I have been successful uploading through Postman before. Note that, as far as I'm aware, a base64-encoded string won't work here, you need the actual binary data. Try this Q&A for using fetch to post a form.
    – sfdcfox
    Oct 14, 2022 at 3:52
  • Thanks again @sfdcfox, I was able to actually insert ContentVersion records this way after some battling with JavaScript, but unfortunately the result is still the same. Be it fetch or XMLHttpRequest, it is extremely slow. It takes about 75 seconds to upload 6 MB of data, and over 8 minutes for 30 MB of data. I am at a bit of a loss as to why it is happening...
    – Bartu
    Oct 14, 2022 at 9:19
  • @Bartu It's unlikely Salesforce being the problem. Try running a Speed Test against your org, see what that looks like. Also, try a different computer or network to rule out the possibility of a local issue. If it really is taking this long, you should probably be contacting support.
    – sfdcfox
    Oct 14, 2022 at 13:09
  • speedtest is OK (above 15Mbit/s upload), octane score is above 60,000. I sent a support ticket earlier today, waiting for a response now. I will update the main post once I get a response.
    – Bartu
    Oct 14, 2022 at 14:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .