Skip to content
This repository was archived by the owner on Jan 10, 2024. It is now read-only.

Commit 728e6aa

Browse files
author
Pat Patterson
committed
jQuery-ized blob sample
1 parent 4ab6f9c commit 728e6aa

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

README.markdown

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,35 @@ Recent Updates
2222

2323
* Inserting or updating blob data using the `create` or `update` functions (passing base64-encoded binary data in JSON) is limited by the REST API to 50 MB of text data or 37.5 MB of base64–encoded data. New functions, `createBlob` and `updateBlob`, allow creation and update of ContentVersion and Document records with binary ('blob') content with a size of up to 500 MB. Here is a minimal sample that shows how to upload a file to Chatter Files:
2424

25-
<apex:page>
26-
<script src="{!$Resource.forcetk_new}"></script>
27-
<p>
28-
Select a file to upload as a new Chatter File.
29-
</p>
30-
<input type="file" id="file" onchange="upload()"/>
31-
<p id="message"></p>
32-
<script>
33-
var client = new forcetk.Client();
34-
client.setSessionToken('{!$Api.Session_ID}');
35-
function upload() {
36-
var file = document.getElementById("file").files[0];
37-
client.createBlob('ContentVersion', {
38-
Origin: 'H', // 'H' for Chatter File, 'C' for Content Document
39-
PathOnClient: file.name
40-
}, file.name, 'VersionData', file, function(response){
41-
console.log(response);
42-
document.getElementById("message").innerHTML =
43-
"Chatter File created: <a href=\"/" + response.id + "\">Take a look!</a>";
44-
}, function(request, status, response){
45-
console.log(response);
46-
document.getElementById("message").innerHTML =
47-
"Error: " + status;
48-
});
49-
}
50-
</script>
25+
<apex:page docType="html-5.0" title="File Uploader">
26+
<h3>
27+
Select a file to upload as a new Chatter File.
28+
</h3>
29+
<input type="file" id="file" onchange="upload()"/>
30+
<p id="message"></p>
31+
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
32+
<script src="{!$Resource.forcetk}"></script>
33+
<script>
34+
var client = new forcetk.Client();
35+
36+
client.setSessionToken('{!$Api.Session_ID}');
37+
38+
function upload() {
39+
var file = $("#file")[0].files[0];
40+
client.createBlob('ContentVersion', {
41+
Origin: 'H', // 'H' for Chatter File, 'C' for Content Document
42+
PathOnClient: file.name
43+
}, file.name, 'VersionData', file, function(response){
44+
console.log(response);
45+
$("#message").html("Chatter File created: <a target=\"_blank\" href=\"/" + response.id + "\">Take a look!</a>");
46+
}, function(request, status, response){
47+
$("#message").html("Error: " + status);
48+
});
49+
}
50+
</script>
5151
</apex:page>
5252

53-
Under the covers, `createBlob` sends a multipart message. See the REST API doc page [Insert or Update Blob Data](https://www.salesforce.com/us/developer/docs/api_rest/Content/dome_sobject_insert_update_blob.htm) for more details.
53+
Under the covers, `createBlob` sends a multipart message. See the REST API doc page [Insert or Update Blob Data](https://www.salesforce.com/us/developer/docs/api_rest/Content/dome_sobject_insert_update_blob.htm) for more details.
5454

5555
Dependencies
5656
------------

0 commit comments

Comments
 (0)