在Google云端硬盘文档文件中动态添加内容

时间:2016-02-03 10:17:40

标签: javascript jquery google-drive-api google-drive-realtime-api

enter image description here我已经创建了动态文件,在我必须添加一些来自fckeditor的动态内容后,在保存按钮上放置该文件如何添加内容或文本。使用PHP中的google驱动程序API的java脚本代码在Google文档文件中添加。

1 个答案:

答案 0 :(得分:0)



function gd_updateFile()
                {
                    var my_text = "your content";

                    var folderId  =  "fileid";
                    var fileId = "your folder id ";


                    const boundary = '-------314159265358979323846';
                    const delimiter = "\r\n--" + boundary + "\r\n";
                    const close_delim = "\r\n--" + boundary + "--";

                    var contentType = "text/html";
                    var metadata = {'mimeType': contentType,};

                    var multipartRequestBody =
                        delimiter +  'Content-Type: application/json\r\n\r\n' +
                        JSON.stringify(metadata) +
                        delimiter + 'Content-Type: ' + contentType + '\r\n' + '\r\n' +
                        my_text +
                        close_delim;


                    var request  = gapi.client.request({
                        'path': '/upload/drive/v2/files/'+folderId+"?fileId="+fileId+"&uploadType=multipart",
                        'method': 'PUT',
                        'params': {'fileId': fileId, 'uploadType': 'multipart'},
                        'headers': {'Content-Type': 'multipart/mixed; boundary="' + boundary + '"'},
                        'body': multipartRequestBody,
                        callback:callback,
                	});



                    $(".update_file_out_put").html(callback);

                	if (!callback) 
                    	{ 
                    		callback = function(file) 
                    		{ 
                            	//console.log(file);
                    		}; 
                    	}
                }