I want to create attachment from javascript to salesforc using REST api without using Ajax Toolkit.

I tried with this link Create Document using REST API

But I had no luck .

Please help.


  • 1
    This one is the same link I mentioned in my question. Jul 21, 2014 at 13:49

1 Answer 1


use Forcetk javascript library as follows - https://github.com/developerforce/Force.com-JavaScript-REST-Toolkit

please find below is the sample code -

<apex:page docType="html-5.0" title="File Uploader">

Select a file to upload as a new Chatter File.

var client = new forcetk.Client();


function upload() {
    var file = $("#file")[0].files[0];
    client.createBlob('ContentVersion', {
        Origin: 'H', // 'H' for Chatter File, 'C' for Content Document
        PathOnClient: file.name
    }, file.name, 'VersionData', file, function(response){
        $("#message").html("Chatter File created: <a target=\"_blank\" href=\"/" + response.id + "\">Take a look!</a>");
    }, function(request, status, response){
        $("#message").html("Error: " + status);

You can refer to this question and answer as well - Uploading attachments using ForceTk

You must log in to answer this question.

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