You need to sign in to do that
Don't have an account?
Khalfe
Using Apex and VF to explore folders and files from google drive
Hi every body,
I'm trying to do an apex class and VF page to explore folders and files from google drive. I need help, I make this code the only think I have it'just and redirection page to google drive.
When I click on "Drives folder" It's show the google drive page. But what I want is to show a window like this
In fact a window like where we can a files or folders,
thanks in advanace
I'm trying to do an apex class and VF page to explore folders and files from google drive. I need help, I make this code the only think I have it'just and redirection page to google drive.
public class MyClass { private String code; public boolean val { get; set; } public blob file { get; set; } public String filetype { get; set; } public String filename { get; set; } public Id ContactId=ApexPages.currentPage().getParameters().get('Id'); public sharingClass() { } public PageReference explor() { //refreshtoken ='GDriveAPI/drive/v3/files/'; //Getting access token from google HttpRequest req = new HttpRequest(); req.setMethod('POST'); req.setEndpoint('https://www.googleapis.com/oauth2/v4/token'); req.setHeader('content-type', 'application/x-www-form-urlencoded'); req.setTimeout(60 * 1000); Http h = new Http(); String resp; HttpResponse res = h.send(req); resp = res.getBody(); System.debug(ContactId); String boundary = '----------9889464542212'; String delimiter = '\r\n--' + boundary + '\r\n'; String close_delim = '\r\n--' + boundary + '--'; //PageReference returnPage = new PageReference('/lightning/r/Contact/'+ContactId+'/view?0.source=alohaHeader'); PageReference returnPage = new PageReference('https://drive.google.com/drive/'); return returnPage; } public static void basicAuthCallout(){ HttpRequest req = new HttpRequest(); req.setEndpoint('callout:GDriveAPI/drive/v3/files/'); req.setMethod('GET'); // Specify the required user name and password to access the endpoint // As well as the header and header information String username = ''; String password = ''; Blob headerValue = Blob.valueOf(username + ':' + password); String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue); req.setHeader('Authorization', authorizationHeader); // Create a new http object to send the request object // A response object is generated as a result of the request Http http = new Http(); HTTPResponse res = http.send(req); System.debug(res.getBody()); } }My Visualforce page, see bellow
<apex:page controller="MyClass" showQuickActionVfHeader="true"> <apex:slds /> <apex:form style="margin-top:5%;margin-left:5%;width:60%"> <apex:pageblock > <br/> <br/> <br/> <br/> <apex:inputfile value="{!file}" contentType="{!filetype}" filename="{!filename}" /> <br/> <br/> <br/> <br/> <apex:commandButton styleClass="myClass" onclick="this.value = 'Drives Folders'" value="Drives Folders" action="{!explor}" /> <br/> <br/> <apex:messages styleClass="error" /> <br/> </apex:pageblock> <apex:pageblock > <!--Folder="{!basicAuthCallout}"--> </apex:pageblock> </apex:form> </apex:page>The result is
When I click on "Drives folder" It's show the google drive page. But what I want is to show a window like this
In fact a window like where we can a files or folders,
thanks in advanace
For further reference you can check the below blog too,
https://initaura.com/file-upload/
I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.
Thanks.