function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
reettik mitrareettik mitra 

how to POST csv file in the google drive using google drive api integration from apex

I have successfully integrated the google api services and also i am abe to create .CSV fine in the google drive.But the data inside the CSV file is null(it must be due to incorrect or in proper body format). Please have a look at the code and tell me where to correct it.
Document doc = new Document(Name = 'documentName', Body = Blob.valueOf(csvFile),  Type = 'csv', ContentType='application/vnd.ms-excel');
Here the csvFile is string which contains the data of the CSV in proper format(including spaces and commas).I have used email and upload services to check the CSV file and recieved exactly what I wanted. So I used the following code for drive upload.
String boundary = 'SalesforceNewsTechnologyStuff';
String delimiter = '\r\n--' + boundary + '\r\n'; 
String close_delim = '\r\n--' + boundary + '--';
String bodyEncoded = EncodingUtil.base64Encode(doc.body);
String body = delimiter + 'Content-Type: application/json\r\n\r\n' + '{ "name" : "' + doc.Name + '",' + ' "mimeType" : "text/csv"}' + delimiter + 'Content-Type: text/application/vnd.ms-excel'  + '\r\n' + 'Content-Transfer-Encoding: base64\r\n' + '\r\n' + bodyEncoded + close_delim;
HttpRequest req = new HttpRequest();
req.setheader('Content-Length',String.valueOf(body.length()));
req.setheader('Content-Type','multipart/related; boundary='+boundary);
req.setMethod('POST'); 
req.setEndpoint('callout:Drive1'); 
req.setBody(body); 
Http h = new Http();
Httpresponse resp = h.send(req);
A blank csv gets created every time this code runs.Can any one suggest me how to add the data in the csv file?

 
ANUTEJANUTEJ (Salesforce Developers) 
Hi Reetik,

>> https://initaura.com/file-upload/#:~:text=Create%20a%20button%20%E2%80%9CUpload%20File,method%20from%20your%20controller%20class.

I found this article I think you can try checking this once.

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
mrferdos mrferdosmrferdos mrferdos
This content is simply exciting and creative.norton.com/setup I have been deciding on a institutional move and this has helped me with one aspect.www.norton.com/setup