You need to sign in to do that
Don't have an account?
Browser compatibility
Hai Greetings of the day...
I wrote a code to upload a files by using the webservices. My code is Executing only in Googlechrome ..But not Executing in other browser ..please assist me to solve problem..i am sending my code...
Controller:
public class sub_FileUploadController{
/*
public PageReference Deletefile() {
DeleteObjectRequest request = new DeleteObjectRequest();
BucketName = bucketName;
Key = FileKey;
S3Response response = s3Client.DeleteObject(request);
return null;
}
*/
public PageReference cancel() {
//string queryChild='SELECT Id,parent__c FROM '+ childName + 'Whereid=:' + AcctId + 'LIMIT 1' ;
// SObject childObject= Database.query(queryChild)[0].getSObjectType().newSObject();
Account_Documents__c A = [SELECT id,parent__c from Account_Documents__c where id=:AcctID];
delete a;
return new PageReference('/'+a.parent__c +'/d?retURL=%2F'+ a.parent__c);
//delete childObject;
//return null;
}
public List<integer> BrowseFile{get;set;}
public string secret {get;set;}
public string key { get ;set; }
public string BucketName{get;set;}
public string BucketName1{get;set;}
public String serverURL {get;set;}
public String AcctID {get;set;}
public String AcctID1 {get;set;}
public String userFileName{get;set;}
public String userFileDescription{get;set;}
public String userFileDescription1{get;set;}
public String filenamehidden{get;set;}
public string Filename{get;set;}
public string fileType{get;set;}
public Boolean onemore{get;set;}
public Decimal fileSize{get;set;}
//private String AWSCredentialName = 'tvarana7';
//Variable for 2nd form(apexform1)
public string fileType1{get;set;}
public Decimal fileSize1{get;set;}
public String filenamehidden1{get;set;}
public string Filename1{get;set;}
string filedescriptionAPI1;
string filetypeAPI1;
string filesizeinbytesAPI1;
String filenameAPI1;
string filedescriptionAPI;
string filetypeAPI;
string filesizeinbytesAPI;
String filenameAPI;
datetime expire = system.now().addMinutes(40);
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": "'+ BucketName+'" } ,'+
// { "acl": "'+ record.Access__c +'" },'+ '{"success_action_status": "201" },'+ '{"content-type":"'+record.Content_Type__c+'"},'+
// '{"success_action_redirect": "https://'+serverurl+'/'+AcctID+'"},' +
'["starts-with", "$key", ""] ]}'; } }
public sub_FileUploadController()
{
secret='bXrMni3+SWcWU60QDDI37hNjllWCY3syswO0EFbF';
key='AKIAIO55ACM6IO2EACFQ';
BucketName='SUBHASH';
BucketName1='tvarana7';
onemore= False;
}
public String getPolicy()
{
return EncodingUtil.base64Encode(Blob.valueOf(policy));
}
public String getSignedPolicy()
{
return make_sig(EncodingUtil.base64Encode(Blob.valueOf(policy)),secret);
}
//tester
public String getHexPolicy() {
String p = getPolicy();
return EncodingUtil.convertToHex(Blob.valueOf(p));
}
private String make_sig(string canonicalBuffer,string secret) {
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;}
private String ChildName;
public void page2onLoad()
{
BrowseFile = new List<integer>();
system.debug('ACCTID:'+AcctID);
for(integer i=1;i<5;i++)
{
if(AcctID==null || AcctID=='')
{
string parentID=ApexPages.currentpage().getparameters().get('id');
string parentName=ApexPages.currentpage().getparameters().get('ParentObjecName');
parentName=parentName.replace('\'','');
string parentQuery='SELECT Id FROM '+ parentName + ' where id=\'' + parentID +'\'';
System.debug('PARENT QUERY:'+parentQuery);
SObject ParentObject=Database.query(parentQuery)[0];
System.debug('ParentObjectID:' + ParentObject.Id);
ChildName=ApexPages.currentpage().getparameters().get('ChildObjectName');
ChildName=ChildName.replace('\'','');
string queryChild='SELECT Id FROM '+ childName;
string parentRef=ApexPages.currentpage().getparameters().get('ParentRefName');
parentRef=parentRef.replace('\'','');
SObject childObject= Database.query(queryChild)[0].getSObjectType().newSObject();
childObject.put(parentRef,ParentObject.id);
insert childObject;
system.debug('ChildObjectID:' + childObject.id);
AcctID=childObject.Id;
serverURL =ApexPages.currentpage().getparameters().get('serverURL');
serverURL =serverURL.replace('\'','');
String urlDomain = serverURL.substring(serverURL.indexOf('://')+3,serverURL.indexOf('/services'));
serverURL = urlDomain;
Filename=childObject.id;
filedescriptionAPI=Apexpages.currentpage().getparameters().get('FILEDESCRIPTIONAPI');
filetypeAPI=Apexpages.currentpage().getparameters().get('FILETYPEAPI');
filesizeinbytesAPI=Apexpages.currentpage().getparameters().get('FILESIZEINBYTESAPI');
filenameAPI=Apexpages.currentpage().getparameters().get('FILENAMEAPI');
}
else
{
String selectfields;
if(filedescriptionAPI!='' && filedescriptionAPI!=null){
selectfields=filedescriptionAPI;}
if(filetypeAPI!='' && filetypeAPI!=null){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filetypeAPI;}
else{
selectfields=filetypeAPI;}
}
if(filesizeinbytesAPI!=null && filesizeinbytesAPI!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filesizeinbytesAPI;}
else{
selectfields=filesizeinbytesAPI;}
}
if(filenameAPI!='null' && filenameAPI!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filenameAPI;}
else{
selectfields=filenameAPI;}
}
if(selectfields!=null && selectfields!=''){
selectfields=selectfields.replace('\'',''); }
system.debug('filenameapi:' + filenameAPI);
system.debug('thequery:' + 'select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID + '\'');
SObject childObject;
if(selectfields!='' && selectfields!=null){
childObject=Database.query('select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID + '\'')[0];}
else{
childObject=Database.query('select id from ' + ChildName + ' where id=\'' + AcctID + '\'')[0];}
if(filenameAPI!='' && filenameAPI!='null'){
filenameAPI=filenameAPI.replace('\'','');
childObject.put(filenameAPI,userFileName);}
if(filedescriptionAPI!='' && filedescriptionAPI!='null'){
filedescriptionAPI=filedescriptionAPI.replace('\'','');
childObject.put(filedescriptionAPI,userFileDescription);}
if(filetypeAPI!='' && filetypeAPI!='null'){
filetypeAPI=filetypeAPI.replace('\'','');
childObject.put(filetypeAPI,filetype);}
if(filesizeinbytesAPI!='null' && filesizeinbytesAPI!=''){
filesizeinbytesAPI=filesizeinbytesAPI.replace('\'','');
childObject.put(filesizeinbytesAPI,(decimal)((fileSize)));}
system.debug('........................filesizeinbytesAPI fileSize........................'+fileSize);
upsert childObject;
}
BrowseFile.add(i);
}
}
//second method
public void page2onLoad1(){
onemore=True;
system.debug('ACCTID1:'+AcctID1);
if(AcctID1==null || AcctID1=='')
{
string parentID=ApexPages.currentpage().getparameters().get('id');
string parentName=ApexPages.currentpage().getparameters().get('ParentObjecName');
parentName=parentName.replace('\'','');
string parentQuery='SELECT Id FROM '+ parentName + ' where id=\'' + parentID +'\'';
System.debug('PARENT QUERY:'+parentQuery);
SObject ParentObject=Database.query(parentQuery)[0];
System.debug('ParentObjectID:' + ParentObject.Id);
ChildName=ApexPages.currentpage().getparameters().get('ChildObjectName');
ChildName=ChildName.replace('\'','');
string queryChild='SELECT Id FROM '+ childName;
string parentRef=ApexPages.currentpage().getparameters().get('ParentRefName');
parentRef=parentRef.replace('\'','');
SObject childObject= Database.query(queryChild)[0].getSObjectType().newSObject();
childObject.put(parentRef,ParentObject.id);
insert childObject;
system.debug('ChildObjectID:' + childObject.id);
AcctID1=childObject.Id;
serverURL =ApexPages.currentpage().getparameters().get('serverURL');
serverURL =serverURL.replace('\'','');
String urlDomain = serverURL.substring(serverURL.indexOf('://')+3,serverURL.indexOf('/services'));
serverURL = urlDomain;
Filename1=childObject.id;
filedescriptionAPI1=Apexpages.currentpage().getparameters().get('FILEDESCRIPTIONAPI');
filetypeAPI1=Apexpages.currentpage().getparameters().get('FILETYPEAPI');
filesizeinbytesAPI1=Apexpages.currentpage().getparameters().get('FILESIZEINBYTESAPI');
filenameAPI1=Apexpages.currentpage().getparameters().get('FILENAMEAPI');
// }
// else
// {
String selectfields;
if(filedescriptionAPI1!='' && filedescriptionAPI1!=null){
selectfields=filedescriptionAPI1;}
if(filetypeAPI1!='' && filetypeAPI1!=null){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filetypeAPI1;}
else{
selectfields=filetypeAPI1;}
}
if(filesizeinbytesAPI1!=null && filesizeinbytesAPI1!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filesizeinbytesAPI1;}
else{
selectfields=filesizeinbytesAPI1;}
}
if(filenameAPI1!='null' && filenameAPI1!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filenameAPI1;}
else{
selectfields=filenameAPI1;}
}
if(selectfields!=null && selectfields!=''){
selectfields=selectfields.replace('\'',''); }
system.debug('filenameapi:' + filenameAPI1);
system.debug('thequery:' + 'select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID1 + '\'');
// SObject childObject;
if(selectfields!='' && selectfields!=null){
childObject=Database.query('select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID1 + '\'')[0];
}
else{
childObject=Database.query('select id from ' + ChildName + ' where id=\'' + AcctID1 + '\'')[0];}
if(filenameAPI1!='' && filenameAPI1!='null'){
filenameAPI1=filenameAPI1.replace('\'','');
childObject.put(filenameAPI1,userFileName);}
if(filedescriptionAPI1!='' && filedescriptionAPI1!='null'){
filedescriptionAPI1=filedescriptionAPI1.replace('\'','');
childObject.put(filedescriptionAPI1,userFileDescription1);}
if(filetypeAPI1!='' && filetypeAPI1!='null'){
filetypeAPI1=filetypeAPI1.replace('\'','');
childObject.put(filetypeAPI1,filetype1);}
if(filesizeinbytesAPI1!='null' && filesizeinbytesAPI1!=''){
filesizeinbytesAPI1=filesizeinbytesAPI1.replace('\'','');
childObject.put(filesizeinbytesAPI1,(decimal)((fileSize1)));}
system.debug('........................filesizeinbytesAPI1 fileSize1........................'+fileSize1);
update childObject;
}
}
VisualforcePage:
VisualForcepage:
<apex:page Controller="sub_FileUploadController" action="{!page2onLoad}" sidebar="false" cache="true" >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset:utf-8">
</meta>
<title>file input Test</title>
</head>
<apex:form id="apexform">
<apex:commandButton onclick="getFileType()" oncomplete="completedfunction();" action="{!page2onLoad}" id="cmdUpload1" value="Upload Filess">
</apex:commandbutton>
<apex:pageblock >
<apex:PageBlocksection title="File Details" columns="1">
<apex:pageblocksectionItem >
<apex:outputLabel value=""/>
<apex:commandButton onclick="getFileType()" oncomplete="completedfunction();" action="{!page2onLoad}" id="cmdUpload1" value="Upload File">
<apex:commandButton action="{!cancel}" value="Cancel"/>
<apex:commandButton action="{!page2onLoad1}" value="Add More"/>
</apex:commandButton>
</apex:pageblocksectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="File Description"/>
<apex:inputtext id="ufdescription" value="{!userfiledescription}" />
</apex:pageBlockSectionItem>
<!--Div Code used to display Progress bar image -->
<div id="display1" width="350">
</div>
</apex:PageBlocksection>
</apex:pageblock>
<apex:inputhidden id="filetypehidden" value="{!filetype}"/>
<apex:inputhidden id="filesizehidden" value="{!filesize}"/>
<apex:inputhidden id="filenamehidden" value="{!filenamehidden}"/>
<input type="hidden" id="submithidden" value="false"/>
<script type="text/javascript">
function getFileType()
{
try
{
var filetype;
var filename;
var filesizeF;
filetype=document.forms['submitform'].elements['file'].value;
document.getElementById('j_id0:apexform:filenamehidden').value=filetype;
filetype=filetype.substring(filetype.indexOf('.',0)+1,filetype.length);
document.getElementById('j_id0:apexform:filetypehidden').value=filetype;
filename=document.forms['submitform'].elements['key'];
if(filetype!='' || filetype!=null)
{
filename.value=filename.value + '.' + filetype;
}
if(navigator.appName!='Microsoft Internet Explorer')
{
try
{
filesizeF=document.forms['submitform'].elements['file'];
<!-- alert(filesizeF.files[0].fileSize);-->
document.getElementById('j_id0:apexform:filesizehidden').value=filesizeF.files[0].fileSize;
//document.getElementById('j_id0:apexform:filesizehidden').value=0;
}
catch(errr)
{
}
}
else
{
document.getElementById('j_id0:apexform:filesizehidden').value=0;
}
if(document.getElementById('j_id0:apexform:filesizehidden').value!=0 && document.getElementById('j_id0:apexform:filesizehidden').value!='undefined' && document.getElementById('j_id0:apexform:filenamehidden').value!=undefined) {
document.getElementById('submithidden').value='true';
return true;
}
else
{
alert('Unable to capture file details..');
document.getElementById('submithidden').value='false';
return false;
}
}
catch(err)
{
alert(err);
return false;
}
}
function completedfunction()
{
try
{
if(document.getElementById('submithidden').value=='true')
{
<!--Code to display Progress bar image -->
var html = '';
html += '<img src="/resource/1323008320000/LoadingImage">';
html += '</img>'
document.getElementById('display1').innerHTML = html;
<!--Code to display Progress bar image end -->
document.forms['submitform'].submit();
} }
catch(err)
{
alert(err);
}
}
</script>
</apex:form>
<form id="submitform"
action="https://s3.amazonaws.com/{!BucketName}"
method="post" enctype="multipart/form-data" >
<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="success_action_redirect" value="https://{!serverURL}/{!AcctID}" /> -->
<input type="hidden" value="{!Filename}" name="key"/>
<apex:outputLabel value="File to upload"/>
<input id="fileid" type="file" size="50" name="file" />
</form>
</html>
</apex:page>
First gut reaction if it's working in Chrome but not other browsers - it's JavaScript related.
Open up the JS console in the non-working browsers and look for any JS errors. SF will stop processing everything if a JS error is encountered.
thanks for ur help .. I saw my error in console bug in internet explorer iam getting an error like this can u help me regarding this . undefined f.style.minWidth=c.. please help me to solve this browse comptablity problem
That line of JS isn't in your posted code. Is it somewhere in the rest of your code?
-Andy
we are facing an issue with Visualforce page redirection on IE 9 when this VF page is called in an iframe on a php page.
This is working as expected on Chrome.
Steps:
1. Called the VF page link in an iframe.
2. On some action, the entire page should redirect to a different page.
3. This is working fine in other browsers.
I'm working through a related but not similar issue with IE9 / VF / Javascript right now. Naturally, it works on all other browsers (IE 6-8, Mozilla-based, Chrome, etc) If I can figure it out I'll share what I found out.
-Andy
Shradha,
Have you tried running IE-9 in Compatibility mode?
Regards,
Lakshman
its nt working we are geeting the error as file unable capture the details.. i saw in the browser comptablity also please help me to solve the problem
yaa i have been worked on internet explorer in comptablity mode but not working ..here we are getting a file unable capture the file datails
I think here is the error:
can you replace whereever you have used the above code with below one and try:
Let me know if it works.
Regards,
Lakshman
but its not working we are getting the same error..unable to capture the details
yaa i have been changed the code but not working in internet explorer and mozilafirefox
...its working in google chrome
details....please can u help me to solve this problem
Yes I will definitely help you Ran, can you please try below code:
Do you have any more details on this like what are you trying to do in the javascript? Is it like uploading a file from local and then submitting it to->https://s3.amazonaws.com/{!BucketName}
Regards,
Lakshman
yes its uploading the files only..we have only that information actual i have already tried that code but not working in IE9 and mozillafirefox............please help me to solve this problem.....
yaa its uploading the files from system ..we have information of
key='AKIAIO55ACM6IO2EACFQ';
BucketName='SUBHASH';
but here its working in google chrome but not working in mozillafirefox ,IE9
please help me to solve the problem i have been changed the code also
Hi There,
Even I am facing a similar issue. We are calling VF pages in an iframe on a PHP site, it works on all the browsers except IE9. The plain VF page without any JS is redirceting but VF page with JS is not redirecting and we are not getting any error, it keeps navigating and create the record in Salesforce but redirection doesnt work. Can anyone help on this ?
Thanks in advance!
Cheers!
Hi,
We have almost fixed this issue and will post the solution soon. Stay tuned....