background image

    

if

(!this.f){ this.errMsg.push('Error: Not set the input file.'); }

    

else

 

if

(this.f.files.length < 1){ this.errMsg.push('Error: Not select a file.'); }

    

else

 {

        

this.fileName = this.f.value;

        

/*

         

* 在尝试直接发送二进制流时失败,改用发送 base64 编码数据。

         

*/

        

this.data = (this.data = this.f.files[0].getAsDataURL())

      

.

substr

(this.data.indexOf(',') + 1);

        

this.length = this.data.length;

        

/*

         

* 文件实际大小

         

*/

        

this.

fileSize

 = this.f.files[0].

fileSize

;

        

/*

         

* 文件类型

         

*/

        

this.contentType = this.f.files[0].

fileType

;

    

}

    

/*

     

* 服务器端接收地址

     

*/

    

this.url = conf.url;

    

if

(!this.url){

 

    

this.errMsg.push('Error: Not set the instance url to send binary.');

  

}

    

/*

     

* 发送数据包的大小。默认 100kb

     

*/

    

this.packageSize = conf.packageSize || 102400;

    

/*

     

* 每次发送数据包大小应为 4 的倍数,确保服务器端转换 base64 编码正确。

     

*/

    

if

(this.packageSize % 4 != 0)

 

    

this.packageSize = parseInt(this.packageSize / 4) * 4;

 

    

this.onSendFinished = conf.onSendFinished || null;

    

this.onSending = conf.onSending || null;

    

this.onError = conf.onError || null;

}
FireFoxFileSender.prototype = {

    

/*

     

* 记录当前发送的数据

     

*/