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
pavan kumar 14pavan kumar 14 

Uploading aws object issue using javascript sdk in IE

Hi All,

I am trying to upload a file in to AWS using AWS Javascript SDK in Visual force Pages. Below is the java script code i have used to upload the file :

function uploadFile() {
       document.getElementById('btnUpload').disabled=true;
        ddocument.getElementById('btnUpload').disabled=true;
        document.getElementById('dvMsg').style.visibility='visible';
     AWS.config.update({ accessKeyId: 'XXXXXXXXXXXXXXXXX', secretAccessKey: 'XXXXXXXXXXXXXXXXXXXXXXX' });
        AWS.config.update({region : 'regionName'});

     var aws_bucket = new AWS.S3({ params: { Bucket: 'bucketName' } });
     
     var fileChooser = document.getElementById('file');

     var file = fileChooser.files[0];

     var aws_err = ''; var timeStamp = '';var aws_data = '';
 
     if (file) {
       
         
         var aws_params = { Key: file.name, ContentType: file.type, Body: file };
         aws_bucket.putObject(aws_params, function (aws_err,aws_data) {
                //results.innerHTML = err ? 'ERROR!' : 'UPLOADED.';
             if(aws_err != null)
                {
                    results.innerHTML = ' Some Error Occured while processing your request, please try after some time.. ';
                    document.getElementById('dvMsg').innerHTML="";
                    }
                else
                    {
         
                document.getElementById('dvMsg').style.visibility='hidden';
                        document.getElementById('dvMsg').innerHTML="UPLOADED";
                        }
             
        });
     } else {
         results.innerHTML = 'Nothing to upload.';
     }
}


The above code worked perfect until 18th April 2014. From 21st April 2014, the same code is throwing error in IE ( but working in Firefox and Chrome) and not working at all.

And the Error is "Object doesn't support property or method 'indexOf' "

Also an update was happened in the salesforce on 18th April 11 PM PST,

Is this update causing an issue??

Please any one help us regarding the issue.
VikashVikash (Salesforce Developers) 
Hi,

Can you please tell me what version of IE you are using because I beleieve IE7,8,9 doesnot support the method "indexof".
Here is a link for the Spring 14 release related to the updates of browser support.

http://docs.releasenotes.salesforce.com/en-us/api/release-notes/rn_general_browsers.htm

Thanks
Vikash_SFDC
PrasanntaPrasannta (Salesforce Developers) 
Hi,

Internet Explore 6,7,8 don’t support indexOf() method on Array while it works fine on Strings.
Try using a regex.
For example-
if (image.indexOf("/bob/") != -1 || image.indexOf("/grabs/") != -1 || image.indexOf("/") == image.lastIndexOf("/")) {
    alert('success');
}

Replace it like this-
if(/\/(bob|ginger|grabs)\//.test(image) || /^[^\/]*\/$/.test(image)){
}

Hope is helps.
pavan kumar 14pavan kumar 14
Hi,

Internet Explorer 10 and 11 versions 

Please any one help us
VikashVikash (Salesforce Developers) 
Hi Pavan,

Please customize your codes as in the sample:

jQuery.inArray( value, array [, fromIndex ] )


As it can work in every browsers 

or you can try like this:

if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function(obj, start) {
         for (var i = (start || 0), j = this.length; i < j; i++) {
             if (this[i] === obj) { return i; }
         }
         return -1;
    }
}

Hope this helps

Thanks
Vikash_SFDC
pavan kumar 14pavan kumar 14
Hi Vikash,Prasannta,


We are not at all calling "indexOf()" method in our code .We are not sure why "indexOf()"  is getting called for uploading the file in to S3 when we call the putObject() function.

Also, if we put our code which we mentioned in the beginning in a HTML file its working fine.... we are getting this 'indexOf' error only when we place our code in a VisualForce Page.

Thanks
ManzaManza
Hey Pavan, 
where you able to fix your issue? I am having the same problem.
I cant understand Vikash solution, 
where exactly you will place, the error gets trigger on line:  aws_bucket.putObject(aws_params, function (aws_err,aws_data) {


if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function(obj, start) {
         for (var i = (start || 0), j = this.length; i < j; i++) {
             if (this[i] === obj) { return i; }
         }
         return -1;
    }
}


?