- Harish Basthapur
- NEWBIE
- 0 Points
- Member since 2013
- Salesforce Developer
-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
6Questions
-
6Replies
On Uploading a File from force.com to amazon S3, How to Round the size of the Files for the files
I am able to build an application which uploads the files from force.com to amazon aws S3,
but also,I need to round the size of the Files uploaded into S3, I had tried with some code like using ifelse
public Blob fileBlob {get;set;} /*Important one*/
public Integer fileSize {get;set;}
public String fileName {get;set;}
.
.
.
.
public pageReference syncFilesystemDoc(){
try
{
system.debug('Entered try suncFileSystemDoc method');
system.debug('FileSize is '+FileSize);
system.debug('accessTypeSelected is'+accessTypeSelected);
Datetime now = Datetime.now();
if(FileSize < 1000.00){
FileSize=1000;}
else if(FileSize <4000.00){
FileSize=4000;}
else if(FileSize <8000.00){
FileSize=8000;}
else{
FileSize= 12000;}
String docBody = EncodingUtil.base64Encode(fileBlob);
System.debug('File blob size is ' + fileBlob);
//TODO - make sure doc.bodyLength is not greater than 100000 to avoid apex limits
System.debug('File size after the ifelse loop is: ' + fileSize);
uploadObjectErrorMsg = 'Error';
Boolean putObjResult = as3.PutObjectInline_ACL(bucketToUploadObject,FolderToUploadObject,fileName,null,docBody,fileSize,accessTypeSelected,as3.key,now,as3.signature('PutObjectInline',now),as3.secret, OwnerId);
if(putObjResult==true){
System.debug('putobjectinline successful');
uploadObjectErrorMsg = 'Success';
}
}catch(System.CalloutException callout){
System.debug('CALLOUT EXCEPTION: ' + callout);
uploadObjectErrorMsg = callout.getMessage();
}catch(Exception ex){
System.debug('EXCEPTION: ' + ex);
uploadObjectErrorMsg = ex.getMessage();
}
return null;
}
Iam able to round the size of the file, which can be observed only through the Force.com Debug log’s only within the Force.com, but in S3 there is some problem , which is not reflected over there, I mean the code is not working.It is perfect for File Upload but "How to Round the size of File/Folder"
Thanx in advance!
-
- Harish Basthapur
- March 25, 2013
- Like
- 0
On Uploading a File from force.com to amazon S3, How to Round the size of the Files for the files
I am able to build an application which uploads the files from force.com to amazon aws S3,
but also,I need to round the size of the Files uploaded into S3, I had tried with some code like using ifelse
public Blob fileBlob {get;set;} /*Important one*/
public Integer fileSize {get;set;}
public String fileName {get;set;}
.
.
.
.
public pageReference syncFilesystemDoc(){
try
{
system.debug('Entered try suncFileSystemDoc method');
system.debug('FileSize is '+FileSize);
system.debug('accessTypeSelected is'+accessTypeSelected);
Datetime now = Datetime.now();
if(FileSize < 1000.00){
FileSize=1000;}
else if(FileSize <4000.00){
FileSize=4000;}
else if(FileSize <8000.00){
FileSize=8000;}
else{
FileSize= 12000;}
String docBody = EncodingUtil.base64Encode(fileBlob);
System.debug('File blob size is ' + fileBlob);
//TODO - make sure doc.bodyLength is not greater than 100000 to avoid apex limits
System.debug('File size after the ifelse loop is: ' + fileSize);
uploadObjectErrorMsg = 'Error';
Boolean putObjResult = as3.PutObjectInline_ACL(bucketToUploadObject,FolderToUploadObject,fileName,null,docBody,fileSize,accessTypeSelected,as3.key,now,as3.signature('PutObjectInline',now),as3.secret, OwnerId);
if(putObjResult==true){
System.debug('putobjectinline successful');
uploadObjectErrorMsg = 'Success';
}
}catch(System.CalloutException callout){
System.debug('CALLOUT EXCEPTION: ' + callout);
uploadObjectErrorMsg = callout.getMessage();
}catch(Exception ex){
System.debug('EXCEPTION: ' + ex);
uploadObjectErrorMsg = ex.getMessage();
}
return null;
}
Iam able to round the size of the file, which can be observed only through the Force.com Debug log’s only within the Force.com, but in S3 there is some problem , which is not reflected over there, I mean the code is not working.It is perfect for File Upload but "How to Round the size of File/Folder"
Thanx in advance!
-
- Harish Basthapur
- March 25, 2013
- Like
- 0
How to Round the blob value for the Files uploaded from Force.com to AmazonS3
Hi,
We are uploading files from force.com to amazon aws S3, but we need to the round the size of the Files/Folders uploaded into S3, this could be acheived by rounding the value of blob property say:
public Blob fileBlob {get;set;} /*Important one*/
public Integer fileSize {get;set;}
public String fileName {get;set;}
How could we acheive this scenario. If possible we are looking to round the file size .
Thanx in advance!
-
- Harish Basthapur
- March 19, 2013
- Like
- 0
Can we retrieve Folders from Amazon aws S3 as we are retrieving Buckets.
Hi ,
can we retrieve Folder which are created in S3 directly to our force.com application as we are retrieving Buckets created in Amazon AWS S3.
We had used the below web service call to list the buckets from amazon S3
/* This method invokes the S3 ListAllMyBuckets web service operation*/ public S3.ListAllMyBucketsResult ListAllMyBuckets(String AWSAccessKeyId,DateTime Timestamp,String Signature) { S3.ListAllMyBuckets_element request_x = new S3.ListAllMyBuckets_element(); S3.ListAllMyBucketsResponse_element response_x; request_x.AWSAccessKeyId = AWSAccessKeyId; request_x.Timestamp = Timestamp; request_x.Signature = Signature; Map<String, S3.ListAllMyBucketsResponse_element> response_map_x = new Map<String, S3.ListAllMyBucketsResponse_element>(); response_map_x.put('response_x', response_x); WebServiceCallout.invoke( this, request_x, response_map_x, new String[]{endpoint_x, '', 'http://s3.amazonaws.com/doc/2006-03-01/', 'ListAllMyBuckets', 'http://s3.amazonaws.com/doc/2006-03-01/', 'ListAllMyBucketsResponse', 'S3.ListAllMyBucketsResponse_element'} ); response_x = response_map_x.get('response_x'); return response_x.ListAllMyBucketsResponse; }
also Some more code
public class ListAllMyBucketsResult { public S3.CanonicalUser Owner; public S3.ListAllMyBucketsList Buckets { get; set; } private String[] Owner_type_info = new String[]{'Owner','http://s3.amazonaws.com/doc/2006-03-01/','CanonicalUser','1','1','false'}; private String[] Buckets_type_info = new String[]{'Buckets','http://s3.amazonaws.com/doc/2006-03-01/','ListAllMyBucketsList','1','1','false'}; private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'}; private String[] field_order_type_info = new String[]{'Owner','Buckets'}; } public class ListAllMyBucketsResponse_element { public S3.ListAllMyBucketsResult ListAllMyBucketsResponse; private String[] ListAllMyBucketsResponse_type_info = new String[]{'ListAllMyBucketsResponse','http://s3.amazonaws.com/doc/2006-03-01/','ListAllMyBucketsResult','1','1','false'}; private String[] apex_schema_type_info = new String[]{'http://s3.amazonaws.com/doc/2006-03-01/','true'}; private String[] field_order_type_info = new String[]{'ListAllMyBucketsResponse'}; }
So, As we can select the buckets from our vf page and upload it to amazon S3 from force.com,Similarly can we retrieve and Select the folders. If yes, Please suggest me the way.....
Thanx in Advance!
-
- Harish Basthapur
- March 18, 2013
- Like
- 0
Inegration of Two Visualforce pages into a single page
Hi,
Below is a Visualforce page: NewS3Object
<apex:page standardController="AWS_S3_Object__c" extensions="S3FormController" action="{!constructor}"> <apex:pageMessages /> <apex:form > <apex:inputHidden value="{!serverURL}" id="hiddenServerURL" /> <script type="text/javascript"> document.getElementById('{!$Component.hiddenServerURL}').value = '{!$Api.Enterprise_Server_URL_140}'; </script> <apex:pageBlock title="New S3 Object" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!save1}" value="Continue" > <!-- <apex:param name="urlParam" value="{!$Api.Enterprise_Server_URL_140}" /> --> </apex:commandButton> </apex:pageBlockButtons> <apex:pageBlockSection title="Step 1: Specify Bucket and Object Name" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Bucket Name" for="b__name" /> <apex:selectList value="{!AWS_S3_Object__c.Bucket_Name__c}" multiselect="false" size="1"> <apex:selectOptions value="{!BucketOptions}" /> </apex:selectList> </apex:pageBlockSectionItem> <br /> <apex:pageBlockSectionItem > <apex:outputLabel value="Destination Folder name" for="objName" /> <apex:inputField value="{!AWS_S3_Object__c.folderName__c}" id="objName" required="true" onblur="popType(this);" /> </apex:pageBlockSectionItem> <br/> <apex:pageBlockSectionItem > <apex:outputLabel value="Destination File Name" for="objName" /> <apex:inputField value="{!AWS_S3_Object__c.File_Name__c}" id="objName" required="true" onblur="popType(this);" /> </apex:pageBlockSectionItem> <br/> <apex:pageBlockSectionItem > <apex:outputLabel value="Content Type" /> <apex:inputField value="{!AWS_S3_Object__c.Content_Type__c}" id="ctype" required="true" > <script type="text/javascript"> function popType(element) { // if there is a suffix , set that value into the content type picklist // add more mime types to the content_type picklist as needed var suffix = element.value.replace(/.*\./,''); if (suffix != null) { document.getElementById('{!$Component.ctype}').value = suffix; } } </script> </apex:inputField> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
the Controller for above page is : S3FormController
public class S3FormController { // public String folderName__c = 'apparelFolder'; public AWSKeys credentials {get;set;} private String AWSCredentialName = 'access_apparel'; //Modify this string variable to be the name of the AWS Credential record that contains the proper AWS keys and secret public string secret { get {return credentials.secret;} } public string key { get {return credentials.key;} } public AWS_S3_Object__c record; // { get { return (AWS_S3_Object__c)con.getRecord(); }} public S3.AmazonS3 as3 { get; private set; } public String serverURL {get;set;} ApexPages.StandardController con; public S3FormController(ApexPages.StandardController stdController) { this.con = stdController; system.debug( con.getRecord() ); try { this.record = [select id,bucket_name__c,content_type__c,folderName__c,file_name__c, access__c from AWS_S3_Object__c where id = :con.getRecord().id limit 1]; } catch( Exception ee) { this.record = new AWS_S3_Object__c(); } //as3 = new S3.AmazonS3(credentials.key,credentials.secret); } /* This method is called when the news3object Visualforce page is loaded. It verifies that the AWS Keys can be found in the AWSKeys__c custom object by the specified name, as set in the string variable AWSCredentialsName. Any errors are added to the ApexPage and displayed in the Visualforce page. */ public PageReference constructor(){ try{ credentials = new AWSKeys(AWSCredentialName); as3 = new S3.AmazonS3(credentials.key,credentials.secret); }catch(AWSKeys.AWSKeysException AWSEx){ System.debug('Caught exception in AWS_S3_ExampleController: ' + AWSEx); ApexPages.Message errorMsg = new ApexPages.Message(ApexPages.Severity.FATAL, AWSEx.getMessage()); ApexPages.addMessage(errorMsg); //throw new AWSKeys.AWSKeysException(AWSEx); //ApexPages.addMessage(AWSEx); } return null; } datetime expire = system.now().addDays(1); String formattedexpire = expire.formatGmt('yyyy-MM-dd')+'T'+ expire.formatGmt('HH:mm:ss')+'.'+expire.formatGMT('SSS')+'Z'; string policy { get {return '{ "expiration": "'+formattedexpire+'","conditions": [ {"bucket": "'+ record.Bucket_Name__c +'" } ,{ "acl": "'+ record.Access__c +'" },'+ // '{"success_action_status": "201" },'+ '{"content-type":"'+record.Content_Type__c+'"},'+ '{"success_action_redirect": "https://'+serverurl+'/'+record.id+'"},' + '["starts-with", "$key", ""] ]}'; } } public String getPolicy() { return EncodingUtil.base64Encode(Blob.valueOf(policy)); } public String getSignedPolicy() { return make_sig(EncodingUtil.base64Encode(Blob.valueOf(policy))); } // tester public String getHexPolicy() { String p = getPolicy(); return EncodingUtil.convertToHex(Blob.valueOf(p)); } //method that will sign private String make_sig(string canonicalBuffer) { String macUrl ; String signingKey = EncodingUtil.base64Encode(Blob.valueOf(secret)); Blob mac = Crypto.generateMac('HMacSHA1', blob.valueof(canonicalBuffer),blob.valueof(Secret)); macUrl = EncodingUtil.base64Encode(mac); return macUrl; } public String bucketToList {get;set;} public List<SelectOption> getBucketOptions(){ try{ Datetime now = Datetime.now(); S3.ListAllMyBucketsResult allBuckets = as3.ListAllMyBuckets( key,now,as3.signature('ListAllMyBuckets',now)); List<SelectOption> options = new List<SelectOption>(); for(S3.ListAllMyBucketsEntry bucket: allBuckets.Buckets.Bucket ){ options.add(new SelectOption(bucket.Name,bucket.Name)); } return options; }catch (System.NullPointerException e) { return null; }catch(Exception ex){ //System.debug(ex); System.debug('caught exception in listallmybuckets'); ApexPages.addMessages(ex); return null; } } public pageReference save1() { con.save(); PageReference p = new PageReference('/apex/news3object2?id='+ con.getRecord().id ); p.getParameters().put('urlParam',serverURL); p.setRedirect(true); return p; } public pageReference page2onLoad(){ PageReference tempPageRef = constructor(); // Need to get the salesforce.com server from the URL System.debug('serverURL: ' + ApexPages.currentPage().getParameters().get('urlParam')); serverURL = ApexPages.currentPage().getParameters().get('urlParam'); //System.debug('serverURL: ' + serverURL); String urlDomain = serverURL.substring(serverURL.indexOf('://')+3,serverURL.indexOf('/services')); System.debug('URL Domain: ' + urlDomain); serverURL = urlDomain; return null; } public static testmethod void t1() { AWS_S3_Object__c a = new AWS_S3_Object__c(); S3FormController s3 = new S3FormController( new ApexPages.StandardController( a ) ); AWSKey__c testKey = new AWSKey__c(name='test keys',key__c='key',secret__c='secret'); insert testKey; s3.AWSCredentialName = testKey.name; s3.constructor(); system.debug( s3.secret + ' '+ s3.key ); system.debug( s3.getpolicy() ); system.debug( s3.getSignedPolicy() ); system.debug( s3.getHexPolicy() ); PageReference pageRef = Page.news3object; pageRef.getParameters().put('urlParam','https://na22.salseforce.com/services/soap/14.0/c/'); Test.setCurrentPage(pageRef); s3.save1(); s3.page2onLoad(); system.debug( s3.getBucketOptions() ); } public static testmethod void t2() { AWS_S3_Object__c a = new AWS_S3_Object__c(); S3FormController s3 = new S3FormController(new ApexPages.StandardController( a ) ); s3.AWSCredentialName = 'bad key name'; s3.constructor(); } }
and when the Button "Continue" is clicked it is redirected to another page with same controller called NewS3Object2
<apex:page standardController="AWS_S3_Object__c" extensions="S3FormController" action="{!page2onLoad}"> <form action="https://s3.amazonaws.com/{!AWS_S3_Object__c.Bucket_Name__c}" method="post" enctype="multipart/form-data"> <input type="hidden" name="key" value="{!AWS_S3_Object__c.folderName__c}/{!AWS_S3_Object__c.File_Name__c}" /> <input type="hidden" name="AWSAccessKeyId" value="{!key}" /> <input type="hidden" name="policy" value="{!policy}" /> <input type="hidden" name="signature" value="{!signedPolicy}" /> <input type="hidden" name="acl" value="{!AWS_S3_Object__c.Access__c}" /> <!-- <input type="hidden" name="success_action_status" value="201"> --> <input type="hidden" name="Content-Type" value="{!AWS_S3_Object__c.Content_Type__c}" /> <input type="hidden" name="success_action_redirect" value="https://{!serverURL}/{!AWS_S3_Object__c.id}" /> <apex:pageBlock title="New S3 Object" mode="edit"> <apex:pageBlockButtons > <input class="btn" type="submit" value="Send to Amazon" /> </apex:pageBlockButtons> <apex:pageBlockSection title="Local File to load" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Storage Path" /> <apex:outputText > {!AWS_S3_Object__c.Bucket_Name__c}/{!AWS_S3_Object__c.folderName__c}/{!AWS_S3_Object__c.File_Name__c} </apex:outputText> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="File to upload" /> <input type="file" size="50" name="file" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock></form> </apex:page>
How to make the Above two visualforce pages namely NewS3Object and NewS3Object2 into a single Visualforce page with same action and properties. Please Suggest me how to do it.
-
- Harish Basthapur
- February 27, 2013
- Like
- 0
Combination of two visualforce pages into a single PAGE
Hi,
-
- Harish Basthapur
- February 27, 2013
- Like
- 0
Inegration of Two Visualforce pages into a single page
Hi,
Below is a Visualforce page: NewS3Object
<apex:page standardController="AWS_S3_Object__c" extensions="S3FormController" action="{!constructor}"> <apex:pageMessages /> <apex:form > <apex:inputHidden value="{!serverURL}" id="hiddenServerURL" /> <script type="text/javascript"> document.getElementById('{!$Component.hiddenServerURL}').value = '{!$Api.Enterprise_Server_URL_140}'; </script> <apex:pageBlock title="New S3 Object" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!save1}" value="Continue" > <!-- <apex:param name="urlParam" value="{!$Api.Enterprise_Server_URL_140}" /> --> </apex:commandButton> </apex:pageBlockButtons> <apex:pageBlockSection title="Step 1: Specify Bucket and Object Name" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Bucket Name" for="b__name" /> <apex:selectList value="{!AWS_S3_Object__c.Bucket_Name__c}" multiselect="false" size="1"> <apex:selectOptions value="{!BucketOptions}" /> </apex:selectList> </apex:pageBlockSectionItem> <br /> <apex:pageBlockSectionItem > <apex:outputLabel value="Destination Folder name" for="objName" /> <apex:inputField value="{!AWS_S3_Object__c.folderName__c}" id="objName" required="true" onblur="popType(this);" /> </apex:pageBlockSectionItem> <br/> <apex:pageBlockSectionItem > <apex:outputLabel value="Destination File Name" for="objName" /> <apex:inputField value="{!AWS_S3_Object__c.File_Name__c}" id="objName" required="true" onblur="popType(this);" /> </apex:pageBlockSectionItem> <br/> <apex:pageBlockSectionItem > <apex:outputLabel value="Content Type" /> <apex:inputField value="{!AWS_S3_Object__c.Content_Type__c}" id="ctype" required="true" > <script type="text/javascript"> function popType(element) { // if there is a suffix , set that value into the content type picklist // add more mime types to the content_type picklist as needed var suffix = element.value.replace(/.*\./,''); if (suffix != null) { document.getElementById('{!$Component.ctype}').value = suffix; } } </script> </apex:inputField> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
the Controller for above page is : S3FormController
public class S3FormController { // public String folderName__c = 'apparelFolder'; public AWSKeys credentials {get;set;} private String AWSCredentialName = 'access_apparel'; //Modify this string variable to be the name of the AWS Credential record that contains the proper AWS keys and secret public string secret { get {return credentials.secret;} } public string key { get {return credentials.key;} } public AWS_S3_Object__c record; // { get { return (AWS_S3_Object__c)con.getRecord(); }} public S3.AmazonS3 as3 { get; private set; } public String serverURL {get;set;} ApexPages.StandardController con; public S3FormController(ApexPages.StandardController stdController) { this.con = stdController; system.debug( con.getRecord() ); try { this.record = [select id,bucket_name__c,content_type__c,folderName__c,file_name__c, access__c from AWS_S3_Object__c where id = :con.getRecord().id limit 1]; } catch( Exception ee) { this.record = new AWS_S3_Object__c(); } //as3 = new S3.AmazonS3(credentials.key,credentials.secret); } /* This method is called when the news3object Visualforce page is loaded. It verifies that the AWS Keys can be found in the AWSKeys__c custom object by the specified name, as set in the string variable AWSCredentialsName. Any errors are added to the ApexPage and displayed in the Visualforce page. */ public PageReference constructor(){ try{ credentials = new AWSKeys(AWSCredentialName); as3 = new S3.AmazonS3(credentials.key,credentials.secret); }catch(AWSKeys.AWSKeysException AWSEx){ System.debug('Caught exception in AWS_S3_ExampleController: ' + AWSEx); ApexPages.Message errorMsg = new ApexPages.Message(ApexPages.Severity.FATAL, AWSEx.getMessage()); ApexPages.addMessage(errorMsg); //throw new AWSKeys.AWSKeysException(AWSEx); //ApexPages.addMessage(AWSEx); } return null; } datetime expire = system.now().addDays(1); String formattedexpire = expire.formatGmt('yyyy-MM-dd')+'T'+ expire.formatGmt('HH:mm:ss')+'.'+expire.formatGMT('SSS')+'Z'; string policy { get {return '{ "expiration": "'+formattedexpire+'","conditions": [ {"bucket": "'+ record.Bucket_Name__c +'" } ,{ "acl": "'+ record.Access__c +'" },'+ // '{"success_action_status": "201" },'+ '{"content-type":"'+record.Content_Type__c+'"},'+ '{"success_action_redirect": "https://'+serverurl+'/'+record.id+'"},' + '["starts-with", "$key", ""] ]}'; } } public String getPolicy() { return EncodingUtil.base64Encode(Blob.valueOf(policy)); } public String getSignedPolicy() { return make_sig(EncodingUtil.base64Encode(Blob.valueOf(policy))); } // tester public String getHexPolicy() { String p = getPolicy(); return EncodingUtil.convertToHex(Blob.valueOf(p)); } //method that will sign private String make_sig(string canonicalBuffer) { String macUrl ; String signingKey = EncodingUtil.base64Encode(Blob.valueOf(secret)); Blob mac = Crypto.generateMac('HMacSHA1', blob.valueof(canonicalBuffer),blob.valueof(Secret)); macUrl = EncodingUtil.base64Encode(mac); return macUrl; } public String bucketToList {get;set;} public List<SelectOption> getBucketOptions(){ try{ Datetime now = Datetime.now(); S3.ListAllMyBucketsResult allBuckets = as3.ListAllMyBuckets( key,now,as3.signature('ListAllMyBuckets',now)); List<SelectOption> options = new List<SelectOption>(); for(S3.ListAllMyBucketsEntry bucket: allBuckets.Buckets.Bucket ){ options.add(new SelectOption(bucket.Name,bucket.Name)); } return options; }catch (System.NullPointerException e) { return null; }catch(Exception ex){ //System.debug(ex); System.debug('caught exception in listallmybuckets'); ApexPages.addMessages(ex); return null; } } public pageReference save1() { con.save(); PageReference p = new PageReference('/apex/news3object2?id='+ con.getRecord().id ); p.getParameters().put('urlParam',serverURL); p.setRedirect(true); return p; } public pageReference page2onLoad(){ PageReference tempPageRef = constructor(); // Need to get the salesforce.com server from the URL System.debug('serverURL: ' + ApexPages.currentPage().getParameters().get('urlParam')); serverURL = ApexPages.currentPage().getParameters().get('urlParam'); //System.debug('serverURL: ' + serverURL); String urlDomain = serverURL.substring(serverURL.indexOf('://')+3,serverURL.indexOf('/services')); System.debug('URL Domain: ' + urlDomain); serverURL = urlDomain; return null; } public static testmethod void t1() { AWS_S3_Object__c a = new AWS_S3_Object__c(); S3FormController s3 = new S3FormController( new ApexPages.StandardController( a ) ); AWSKey__c testKey = new AWSKey__c(name='test keys',key__c='key',secret__c='secret'); insert testKey; s3.AWSCredentialName = testKey.name; s3.constructor(); system.debug( s3.secret + ' '+ s3.key ); system.debug( s3.getpolicy() ); system.debug( s3.getSignedPolicy() ); system.debug( s3.getHexPolicy() ); PageReference pageRef = Page.news3object; pageRef.getParameters().put('urlParam','https://na22.salseforce.com/services/soap/14.0/c/'); Test.setCurrentPage(pageRef); s3.save1(); s3.page2onLoad(); system.debug( s3.getBucketOptions() ); } public static testmethod void t2() { AWS_S3_Object__c a = new AWS_S3_Object__c(); S3FormController s3 = new S3FormController(new ApexPages.StandardController( a ) ); s3.AWSCredentialName = 'bad key name'; s3.constructor(); } }
and when the Button "Continue" is clicked it is redirected to another page with same controller called NewS3Object2
<apex:page standardController="AWS_S3_Object__c" extensions="S3FormController" action="{!page2onLoad}"> <form action="https://s3.amazonaws.com/{!AWS_S3_Object__c.Bucket_Name__c}" method="post" enctype="multipart/form-data"> <input type="hidden" name="key" value="{!AWS_S3_Object__c.folderName__c}/{!AWS_S3_Object__c.File_Name__c}" /> <input type="hidden" name="AWSAccessKeyId" value="{!key}" /> <input type="hidden" name="policy" value="{!policy}" /> <input type="hidden" name="signature" value="{!signedPolicy}" /> <input type="hidden" name="acl" value="{!AWS_S3_Object__c.Access__c}" /> <!-- <input type="hidden" name="success_action_status" value="201"> --> <input type="hidden" name="Content-Type" value="{!AWS_S3_Object__c.Content_Type__c}" /> <input type="hidden" name="success_action_redirect" value="https://{!serverURL}/{!AWS_S3_Object__c.id}" /> <apex:pageBlock title="New S3 Object" mode="edit"> <apex:pageBlockButtons > <input class="btn" type="submit" value="Send to Amazon" /> </apex:pageBlockButtons> <apex:pageBlockSection title="Local File to load" columns="1"> <apex:pageBlockSectionItem > <apex:outputLabel value="Storage Path" /> <apex:outputText > {!AWS_S3_Object__c.Bucket_Name__c}/{!AWS_S3_Object__c.folderName__c}/{!AWS_S3_Object__c.File_Name__c} </apex:outputText> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="File to upload" /> <input type="file" size="50" name="file" /> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock></form> </apex:page>
How to make the Above two visualforce pages namely NewS3Object and NewS3Object2 into a single Visualforce page with same action and properties. Please Suggest me how to do it.
- Harish Basthapur
- February 27, 2013
- Like
- 0