You need to sign in to do that
Don't have an account?

How to create a file inside a folder in google drive?
I am able to create a file in Google drive with the below code:
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setEndpoint('https://www.googleapis.com/upload/drive/v2/files?uploadType=media');
req.setHeader('content-type', 'text/plain');
req.setHeader('Authorization','Bearer '+accessToken);
String messageBody = 'Hi, This message is from Salesforce';
req.setBody(messageBody);
req.setTimeout(60*1000);
HttpResponse resp = http.send(req);
But now i want to create a file inside a folder in Google drive. I am using end point as:
req.setEndpoint('https://www.googleapis.com/upload/drive/v2/files/0B602YDdndVQ6b3RnR2NYQXo5TXM/children?uploadType=media');
where 0B602YDdndVQ6b3RnR2NYQXo5TXM is the folder id.
Can someone please tell me what other changes i have to do in the above code in order to create the file inside a folder?
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setEndpoint('https://www.googleapis.com/upload/drive/v2/files?uploadType=media');
req.setHeader('content-type', 'text/plain');
req.setHeader('Authorization','Bearer '+accessToken);
String messageBody = 'Hi, This message is from Salesforce';
req.setBody(messageBody);
req.setTimeout(60*1000);
HttpResponse resp = http.send(req);
But now i want to create a file inside a folder in Google drive. I am using end point as:
req.setEndpoint('https://www.googleapis.com/upload/drive/v2/files/0B602YDdndVQ6b3RnR2NYQXo5TXM/children?uploadType=media');
where 0B602YDdndVQ6b3RnR2NYQXo5TXM is the folder id.
Can someone please tell me what other changes i have to do in the above code in order to create the file inside a folder?
public void CreateFile(){
String boundary = '----------9889464542212';
String delimiter = '\r\n--' + boundary +'\r\n';
String close_delim = '\r\n--' + boundary + '--';
ApexPages.PageReference report = new ApexPages.PageReference('https://cs2.salesforce.com/00OR0000001FMn2?export=0&enc=UTF-8&xf=csv');
String before='';
//Get the folder ID having file
Google_Drive_Info__c g=new Google_Drive_Info__c();
g=[SELECT Folder_Id__c FROM Google_Drive_Info__c WHERE Name=:'main'];
String FolderId=g.Folder_Id__c;
// create a blob from our parameter value before we send it as part of the url
Blob beforeblob = Blob.valueOf(before);
String bodyEncoded = EncodingUtil.base64Encode(beforeblob);
String filename='Sample_fileNameWithoutExtension';
String filetype='text/csv';
String body=delimiter+'Content-Type: application/json\r\n\r\n'+'{ "title" : "'+ filename+'",'+ ' "mimeType" : "'+ filetype+ '",' + '"parents":[{"id":"'+ FolderId +'"}] }'+delimiter+'Content-Type: ' + filetype + '\r\n'+'Content-Transfer-Encoding: base64\r\n'+'\r\n'+bodyEncoded+close_delim;
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart&convert=true');
req.setHeader('Authorization', 'Bearer ' +access_token);
req.setHeader('Content-Type', 'multipart/mixed; boundary="'+boundary+'"');
req.setHeader('Content-length', String.valueOf(body.length()));
req.setBody(body);
req.setMethod('POST');
req.setTimeout(60*1000);
HttpResponse resp = http.send(req);
filetype='';
filename='';
}
Give a like if this solves your purpose!!!
I want to delete the files which is we created in the google drive folder from the salesforce vf page. do you have any approaches...??
TIA