+ Start a Discussion
vinay maladkar 11vinay maladkar 11 

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

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');

                    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.