Currently I'm working on Google Drive integration with Salesforce. I was able to connect to Google Drive and retrieve a list of file information. now I need to download some files from Google Drive. For that I'm using following method:
public PageReference downloadFile(FileWrapper file){
//webContentLink
if(file == null || file.id == null){
return null;
}
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setMethod('GET');
req.setEndpoint('https://www.googleapis.com/drive/v2/files/'+ file.id+'?alt=media');
req.setHeader('Content-Type', 'application/json');
req.setHeader('Authorization', 'Bearer ' + accessToken);
req.setTimeout(60 * 1000);
HttpResponse resp = null;
resp = http.send(req);
test = resp.getBody();
if(resp.getStatusCode() == 200){
PageReference pageref = new PageReference(resp.getBody());
return pageref;
}
return null;
}
When I run this method I'm getting Maximum view state size limit (135KB) exceeded. Actual view state size for this page was 189.844KB. Is there are any other way to download file other than using PageReference? Please help me to sort out this problem. If you guys have any other better way please suggest.
transient
modifier?test = resp.getBody();
as this variable is increasing the viewstate size and is not used anywhere.