- Syntax highlighting
- Collaboration
- Built-in color picker
- HTML preview
- Autocomplete
- Javascript console
- A notepad to jot down ideas
- Built-in todo list
- Browser
- Keyboard shortcuts
- Vim modes
- Preferences
- Google Drive integration
var reader = new FileReader(); reader.readAsBinaryString(fileData); reader.onload = function(e) { var contentType = fileData.type || 'application/octet-stream'; var metadata = { 'title': "untitled.txt", 'mimeType': contentType };
var base64Data = btoa(reader.result);
var multipartRequestBody =
delimiter +
'Content-Type: application/json\r\n\r\n' +
JSON.stringify(metadata) +
delimiter +
'Content-Type: ' + contentType + '\r\n' +
'Content-Transfer-Encoding: base64\r\n' +
'\r\n' +
base64Data +
close_delim;
var request = gapi.client.request({
'path': '/upload/drive/v2/files',
'method': 'POST',
'params': {'uploadType': 'multipart'},
'headers': {
'Content-Type': 'multipart/mixed; boundary="' + boundary + '"'
},
'body': multipartRequestBody});
if (!callback) {
callback = function(file) {
};
}
request.execute(callback);
} }
<h6>Saving a file</h6>
```javascript
function saveFile(fileId, content){
//console.log(content);
if(typeof content !== "undefined"){ //if nothing is "null"
var contentArray = new Array(content.length);
for (var i = 0; i < contentArray.length; i++) {
contentArray[i] = content.charCodeAt(i);
}
var byteArray = new Uint8Array(contentArray);
var blob = new Blob([byteArray], {type: 'text/plain'}); //this is the only way I could get this to work
var request = gapi.client.drive.files.get({'fileId': fileId});//gets the metadata, which is left alone
request.execute(function(resp) {
//console.log(content);
updateFile(fileId,resp,blob,changesSaved);
});
}
}
function updateFile(fileId, fileMetadata, fileData, callback) { //is the callback necessary?
if(ok){
const boundary = '-------314159265358979323846';
const delimiter = "\r\n--" + boundary + "\r\n";
const close_delim = "\r\n--" + boundary + "--";
var reader = new FileReader();
reader.readAsBinaryString(fileData);
reader.onload = function(e) {
var contentType = fileData.type || 'application/octet-stream';
var base64Data = btoa(reader.result);
//console.log(base64Data);
var multipartRequestBody =
delimiter +
'Content-Type: application/json\r\n\r\n' +
JSON.stringify(fileMetadata) +
delimiter +
'Content-Type: ' + contentType + '\r\n' +
'Content-Transfer-Encoding: base64\r\n' +
'\r\n' +
base64Data +
close_delim;
var request = gapi.client.request({
'path': '/upload/drive/v2/files/' + fileId,
'method': 'PUT',
'params': {'uploadType': 'multipart', 'alt': 'json'},
'headers': {
'Content-Type': 'multipart/mixed; boundary="' + boundary + '"'
},
'body': multipartRequestBody});
if (!callback) {//this isn't necessary
callback = function(file) {
//console.log(file) //for some reason, this is important
};
}
request.execute(callback);//not needed
}
}
}