function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vinay maladkar 11vinay maladkar 11 

How to upoload file (content version) to an opportunity using javascript

Hi,
I have a requirement to upload a local csv file to an opportunity throught javascript code - I read "https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_insert_update_blob.htm" post and tried the jquery POST but no success.

var data = new FormData();
                data.append('entity_content', JSON.stringify({
                    contentDocumentId: '06936000002p8gFAAQ',
                    title: 'sample from js'
                }));
                data.append('versionData', $inputFileSelector[0].files[0], 'sample csv.csv');

                $.ajax({
                    url: url,
                    method: "POST",
                    headers: {
                        "Content-Type": 'multipart/form-data',
                        "Authorization": "Bearer " + sessionId
                    },
                    data: data,
                    cache: false,
                    processData: false
                })

Please help me on how to upload local file to opportunity using api in jquery.

Thanks
Vinay