0

Hi I am trying to drag and drop the files into my Custom Object.i.e Inline Vf Page.I can select multiple files but i am unable to drag and drop files in "Internet Explorer".But It works in Chrome.I tried the below code

Visual Force Page

<apex:page standardController="Account__C" extensions="AttachmentActionFunction">
<script type='text/javascript'>



 var newWin=null;
 function openLookupPopup()
 {
  var url="/apex/docutype/";

  alert('$$$$$$$$$$'+ur1);
  newWin=window.open(url, 'Popup','height=500,width=600,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');



    }

 function closeLookupPopup()
 {
    if (null!=newWin)
    {
       newWin.close();
    }  
 }



var maxStringSize = 6000000;
var attachmentList;
var j;
function uploadFiles()
{
    input = document.getElementById('fileinput');
    attachmentList = input.files;
    if(j == undefined) 
    j = 0;   
    var file;
    if(j < attachmentList.length)
    {
        file = attachmentList[j];
     var name = file.name;
        var reader = new FileReader();  
        reader.onload = function(e) {  
         var attachmentbodybase64 = window.btoa(reader.result)
            console.log(attachmentbodybase64.length);
            if(attachmentbodybase64.length > maxStringSize )
            alert("File size is too large to handle");
            else
            {
                j++;
                saveFileAF(attachmentbodybase64, name);
            }
        }
         reader.readAsDataURL(file);
    }
    else
    {
        console.log('this is end');
        var url = window.location.origin + '/'+"{!$CurrentPage.parameters.Id}";
        console.log(url);
        window.location.href = url;
    }

 }
</script>

<script>
function test(){

var url="/apex/docutype";

newWin=window.open(url, 'Popup','height=500,width=600,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');
    console.log('$$$$$$$$$$'+ur1);
    if (window.focus) 
  {
   newWin.focus();
  }

     return false;


}
</script>

<apex:form >
  <input type= "file" Id= "fileinput"  multiple="multiple" />
     <apex:commandButton value="Upload" onclick="test(); return false;" />
    <apex:actionFunction name="saveFileAF" 
         action="{!saveFile}" oncomplete="test()" rerender="form"  status="uploading">
        <apex:param name="base64File" value="" assignTo="{!base64}"/>
        <apex:param name="fileName" value="" assignTo="{!fileName}"/>
    </apex:actionFunction>
    <apex:actionStatus id="uploading" >
        <apex:facet name="start" >
            <img src="/img/loading.gif" />                    
  </apex:facet>
 </apex:actionStatus>    
</apex:form>
</apex:page>

Apex Controller

public class AttachmentActionFunction {

 public transient String base64;
    public account__C Ins;

   public List<Attachment> mulfiles{get;set;}

public Pagereference gotonewpage()
{     
     PageReference pageRef = Page.AttachmentActionFunction;
     pageRef.getParameters().put('msg','success');
     return PageRef;
}   

    public AttachmentActionFunction() {
     mulfiles=new List<Attachment>();

    }



    public String getBase64()
    {
        return base64;
    }
    public void setbase64(String base64)
    {
        this.base64 = base64;
    }
    public String fileName {get; set;}
    public AttachmentActionFunction(ApexPages.StandardController std)
    {
        Ins = (Account__C)std.getRecord();
    }
    public void saveFile()
    {
        Attachment a = new Attachment(parentId = Ins.id, Body =  EncodingUtil.base64Decode(base64), name = fileName);

        mulfiles=new List<Attachment>();


        mulfiles.add(a);
        //insert a;

    }



     public PageReference saveinline() {
        return null;
    }


}

1 Answer 1

1

As you could guess, readAsDataURL is not supported by IE. Try readAsArrayBuffer in the event readAsDataURL is undefined:

var reader = new FileReader();
reader.file = file;
var fileContent;
if (FileReader.prototype.readAsDataURL === undefined) {
    reader.onload = function (e) {  //IE
        var data = "";
        var bytes = new Uint8Array(reader.result);
        var length = bytes.byteLength;
        for (var i = 0; i < length; i++) {
            data += String.fromCharCode(bytes[i]);
        }
        fileContent = window.btoa(data);
        console.log(fileContent);
    };
    reader.readAsArrayBuffer(file);
}else{
    reader.onload = function(evt){
        //your current code
    };
    reader.readAsDataURL(file);
}

Hope that can help.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .