@@ -601,6 +601,211 @@ $('#stop_load').on('click', function(){
601
601
推荐一个关于 [CORS](http://enable-cors.org/) 的网站
602
602
603
603
<a id="contribute-code"></a>
604
+
605
+ **10.Android自带的Webview对JS SDK不支持 **
606
+ 在Android自带的Webview里面引用JS SDK的demo(http://jssdk.demo.qiniu.io/) :
607
+ ```
608
+ public class MainActivity extends Activity {
609
+ private WebView webview;
610
+ @Override
611
+ protected void onCreate(Bundle savedInstanceState) {
612
+ super.onCreate(savedInstanceState);
613
+ setContentView(R.layout.activity_main);
614
+ webview = (WebView) findViewById(R.id.wv);
615
+ webview.getSettings().setJavaScriptEnabled(true);
616
+ webview.setWebViewClient(new WebViewClient(){
617
+ public boolean shouldOverrideUrlLoading(WebView view, String url){
618
+ view.loadUrl(url);
619
+ return true;
620
+ }
621
+ });
622
+ webview.loadUrl("http://demos.qiniu.com/demo/simpleuploader/ ");
623
+ }
624
+
625
+ }
626
+ ```
627
+ 但是点击选择文件按钮没有反应,这个是Webview对JS不是很支持造成的,解决方法可以引入这个Webview,jar包地址如下:
628
+ https://github.com/delight-im/Android-AdvancedWebView/blob/master/JARs/Android-AdvancedWebView.jar
629
+ 使用的方法文档上都有写,比较简单:
630
+ ```
631
+ private AdvancedWebView mWebView;
632
+ @Override
633
+ protected void onCreate(Bundle savedInstanceState) {
634
+ super.onCreate(savedInstanceState);
635
+ setContentView(R.layout.activity_main);
636
+
637
+ mWebView = (AdvancedWebView) findViewById(R.id.webview);
638
+ mWebView.setListener(this, this);
639
+ mWebView.loadUrl("http://jssdk.demo.qiniu.io/");
640
+ }
641
+ ```
642
+
643
+ **11.关于多个按钮选择文件的Demo **
644
+
645
+ 很多用户都在问JSSDK多文件选择的Demo,其实比较简单,只需要在main.js文件里面多new几个Uploader对象就可以了,然后在主页面上里面写好对应的上传的按钮就可以了
646
+ 这里直接给出main.js和indxe.html里面需要改动的地方:
647
+ main.js里面多new几个uploader对象
648
+ ```
649
+ $(function() {
650
+ var uploader = Qiniu.uploader({
651
+ runtimes: 'html5,flash,html4',
652
+ browse_button: 'pickfiles',
653
+ container: 'container',
654
+ drop_element: 'container',
655
+ max_file_size: '100mb',
656
+ flash_swf_url: 'js/plupload/Moxie.swf',
657
+ dragdrop: true,
658
+ chunk_size: '4mb',
659
+ uptoken:'um6IEH7mtwnwkGpjImD08JdxlvViuELhI4mFfoeL:79ApUIePTtKIdVGDHJ9D9BfBnhE=: eyJzY29wZSI6ImphdmFkZW1vIiwiZGVhZGxpbmUiOjE0NTk4ODMyMzV9Cg ==',
660
+ // uptoken_url: $('#uptoken_url').val(), //当然建议这种通过url的方式获取token
661
+ domain: $('#domain').val(),
662
+ auto_start: false,
663
+ init: {
664
+ 'FilesAdded': function(up, files) {
665
+ $('table').show();
666
+ $('#success').hide();
667
+ plupload.each(files, function(file) {
668
+ var progress = new FileProgress(file, 'fsUploadProgress');
669
+ progress.setStatus("等待...");
670
+ });
671
+ },
672
+ 'BeforeUpload': function(up, file) {
673
+ var progress = new FileProgress(file, 'fsUploadProgress');
674
+ var chunk_size = plupload.parseSize(this.getOption('chunk_size'));
675
+ if (up.runtime === 'html5' && chunk_size) {
676
+ progress.setChunkProgess(chunk_size);
677
+ }
678
+ },
679
+ 'UploadProgress': function(up, file) {
680
+ var progress = new FileProgress(file, 'fsUploadProgress');
681
+ var chunk_size = plupload.parseSize(this.getOption('chunk_size'));
682
+
683
+ progress.setProgress(file.percent + "%", file.speed, chunk_size);
684
+ },
685
+ 'UploadComplete': function() {
686
+ $('#success').show();
687
+ },
688
+ 'FileUploaded': function(up, file, info) {
689
+ var progress = new FileProgress(file, 'fsUploadProgress');
690
+ progress.setComplete(up, info);
691
+ },
692
+ 'Error': function(up, err, errTip) {
693
+ $('table').show();
694
+ var progress = new FileProgress(err.file, 'fsUploadProgress');
695
+ progress.setError();
696
+ progress.setStatus(errTip);
697
+ }
698
+ }
699
+ });
700
+
701
+ uploader.bind('FileUploaded', function() {
702
+ console.log('hello man,a file is uploaded');
703
+ });
704
+
705
+ $('#up_load').on('click', function(){
706
+ uploader.start();
707
+ });
708
+ $('#stop_load').on('click', function(){
709
+ uploader.stop();
710
+ });
711
+
712
+ var Q2 = new QiniuJsSDK();
713
+ var uploader2 = Q2.uploader({
714
+ runtimes: 'html5,flash,html4',
715
+ browse_button: 'pickfiles2',
716
+ container: 'container2',
717
+ drop_element: 'container2',
718
+ max_file_size: '100mb',
719
+ flash_swf_url: 'js/plupload/Moxie.swf',
720
+ dragdrop: true,
721
+ chunk_size: '4mb',
722
+ uptoken:'um6IEH7mtwnwkGpjImD08JdxlvViuELhI4mFfoeL:79ApUIePTtKIdVGDHJ9D9BfBnhE=:eyJzY29wZSI6ImphdmFkZW1vIiwiZGVhZGxpbmUiOjE0NTk4ODMyMzV9Cg==',
723
+ // uptoken_url: $('#uptoken_url').val(), //当然建议这种通过url的方式获取token
724
+ domain: $('#domain').val(),
725
+ auto_start: false,
726
+ init: {
727
+ 'FilesAdded': function(up, files) {
728
+ $('table').show();
729
+ $('#success').hide();
730
+ plupload.each(files, function(file) {
731
+ var progress = new FileProgress(file, 'fsUploadProgress');
732
+ progress.setStatus("等待...");
733
+ });
734
+ },
735
+ 'BeforeUpload': function(up, file) {
736
+ var progress = new FileProgress(file, 'fsUploadProgress');
737
+ var chunk_size = plupload.parseSize(this.getOption('chunk_size'));
738
+ if (up.runtime === 'html5' && chunk_size) {
739
+ progress.setChunkProgess(chunk_size);
740
+ }
741
+ },
742
+ 'UploadProgress': function(up, file) {
743
+ var progress = new FileProgress(file, 'fsUploadProgress');
744
+ var chunk_size = plupload.parseSize(this.getOption('chunk_size'));
745
+
746
+ progress.setProgress(file.percent + "%", file.speed, chunk_size);
747
+ },
748
+ 'UploadComplete': function() {
749
+ $('#success').show();
750
+ },
751
+ 'FileUploaded': function(up, file, info) {
752
+ var progress = new FileProgress(file, 'fsUploadProgress');
753
+ progress.setComplete(up, info);
754
+ },
755
+ 'Error': function(up, err, errTip) {
756
+ $('table').show();
757
+ var progress = new FileProgress(err.file, 'fsUploadProgress');
758
+ progress.setError();
759
+ progress.setStatus(errTip);
760
+ }
761
+ }
762
+ });
763
+
764
+ uploader2.bind('FileUploaded', function() {
765
+ console.log('hello man 2,a file is uploaded');
766
+ });
767
+ $('#up_load2').on('click', function(){
768
+ uploader2.start();
769
+ });
770
+ $('#stop_load2').on('click', function(){
771
+ uploader2.stop();
772
+ });
773
+ ```
774
+ 相应的index.html文件加入相关按钮:
775
+ ```
776
+ <div id =" container " >
777
+ <a class="btn btn-default btn-lg " id="pickfiles" style="width:160px" href="#" >
778
+ <i class="glyphicon glyphicon-plus"></i>
779
+ <span>选择文件</span>
780
+ </a>
781
+
782
+ <a class="btn btn-default btn-lg " id="up_load" style="width:160px" href="#" >
783
+ <span>确认上传</span>
784
+ </a>
785
+
786
+ <a class="btn btn-default btn-lg " id="stop_load" style="width:160px" href="#" >
787
+ <span>暂停上传</span>
788
+ </a>
789
+ </div>
790
+
791
+ <div id =" container2 " >
792
+ <a class="btn btn-default btn-lg " id="pickfiles2" style="width:160px" href="#" >
793
+ <i class="glyphicon glyphicon-plus"></i>
794
+ <span>选择文件</span>
795
+ </a>
796
+
797
+ <a class="btn btn-default btn-lg " id="up_load2" style="width:160px" href="#" >
798
+ <span>确认上传</span>
799
+ </a>
800
+
801
+ <a class="btn btn-default btn-lg " id="stop_load2" style="width:160px" href="#" >
802
+ <span>暂停上传</span>
803
+ </a>
804
+ </div>
805
+ </div >
806
+ ```
807
+
808
+
604
809
### 贡献代码
605
810
606
811
1. 登录 https://github.com
0 commit comments