简体   繁体   English

多文件上传:JavaScript和SQL插入

[英]Multi File Upload: Javascript and SQL Insert

Using the following HTML input and Javascript, a user can add up to 3 files to a page. 使用以下HTML输入和Javascript,用户最多可以在一个页面上添加3个文件。

Code for the file upload input: 文件上传输入的代码:

    <input id="my_file_element" type="file" name="file_1" >
    <input type="submit">
Files:
<div id="files_list"></div>
<script> 
    var multi_selector = new MultiSelector( document.getElementById( 'files_list' ), 3 );
    multi_selector.addElement( document.getElementById( 'my_file_element' ) );
</script>

JavaScript in the HTML Header: HTML标头中的JavaScript:

<script language="javascript"> 

    function MultiSelector( list_target, max ){

    this.list_target = list_target;

    this.count = 0;

    this.id = 0;

    if( max ){
        this.max = max;
    } else {
        this.max = -1;
    };

    this.addElement = function( element ){


        if( element.tagName == 'INPUT' && element.type == 'file' ){

            element.name = 'file_' + this.id++;


            element.multi_selector = this;

            element.onchange = function(){

                var new_element = document.createElement( 'input' );
                new_element.type = 'file';

                this.parentNode.insertBefore( new_element, this );

                this.multi_selector.addElement( new_element );

                this.multi_selector.addListRow( this );

                this.style.position = 'absolute';
                this.style.left = '-1000px';

            };

            if( this.max != -1 && this.count >= this.max ){
                element.disabled = true;
            };

            this.count++;

            this.current_element = element;

        } else {
            alert( 'Error: not a file input element' );
        };

    };

    this.addListRow = function( element ){


        var new_row = document.createElement( 'div' );


        var new_row_button = document.createElement( 'input' );
        new_row_button.type = 'button';
        new_row_button.value = 'Delete';

        new_row.element = element;


        new_row_button.onclick= function(){

            this.parentNode.element.parentNode.removeChild( this.parentNode.element );

            this.parentNode.parentNode.removeChild( this.parentNode );


            this.parentNode.element.multi_selector.count--;

            this.parentNode.element.multi_selector.current_element.disabled = false;

            return false;
        };

        new_row.innerHTML = element.value;

        new_row.appendChild( new_row_button );

        this.list_target.appendChild( new_row );

    };

};
    </script>

How do I get the blob files (up to 3) inserted into Oracle DB using Pl/SQL? 如何使用Pl / SQL将Blob文件(最多3个)插入Oracle DB?

What a can of worms. 一罐蠕虫。 I've looked around a bit, and all i can tell you is that what you want to do is not easy at all. 我环顾了一下,我只能告诉你的是,要完成的工作并不容易。 There are several problems you'll have to work around. 您必须解决一些问题。 But, if you are interested, a brave person made a plugin available with multi-file upload (at a price). 但是,如果您有兴趣,那么一个勇敢的人可以使用多文件上传功能 (价格不菲) 提供一个插件

The main issue is that Apex has no way of handling file uploads through AJAX. 主要问题是Apex无法处理通过AJAX上传的文件。 From the documentation of the plugin you can glean some info: files are processed in chunks, to be reconstructed at the end. 从插件的文档中,您可以收集一些信息:文件将按块进行处理,最后进行重构。 In IE (and non-html5 browsers (and IE9 also has no FileReader object)) the files are processed one by one through a seperate page and through an iframe. 在IE(和非html5浏览器(而且IE9也没有FileReader对象))中,文件通过单独的页面和iframe一张一张地处理。 Presumably, this page has a file browse item. 大概此页面上有一个文件浏览项。 I believe files will also be uploaded right away. 我相信文件也会立即上传。

Another way would perhaps be through apex listener . 另一种方法可能是通过顶点监听器 Although here you'll have to figure out even more to get this to work. 尽管在这里您将不得不想出更多办法来使它起作用。

However, when you say 'upload files (up to 3)', does this mean that you can only upload up to 3 files max? 但是,当您说“上传文件(最多3个)”时,这是否意味着最多只能上传3个文件? In that case, why don't you create 3 file browse items, which you then dynamically show/hide? 在那种情况下,为什么不创建3个文件浏览项目,然后动态显示/隐藏它们? Save yourself the trouble of trying to mimic the multi-file plugin. 避免尝试模仿多文件插件的麻烦。

If you do want, the best route would perhaps be the use of an extra page, especially when using IE. 如果您愿意,最好的方法可能是使用额外的页面,尤其是在使用IE时。

In HTML5 browsers you could try the FileReader object in javascript, read the file and encode it, then process it in chunks and put it back together serverside through plsql. 在HTML5浏览器中,您可以尝试使用javascript使用FileReader对象,读取文件并对其进行编码,然后将其分块处理,然后通过plsql将其放回服务器端。 For more info on that, check Reading local files in javascript and Html5 File Upload with Progress . 有关更多信息,请选中使用javascript读取本地文件带有Progress的Html5文件上传

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM