Topic: Original file name remains after attempts to rename file in script

In reference to the following topics already on other plupload forums, I am trying to change the name of a file prior to uploading it. The name of the file is reflected in the widget, but the file name comes across as the original name when submitted.

Help w/file renaming
http://www.plupload.com/punbb/viewtopic.php?id=1008

Can I change file name of uploaded files on the client side?
http://www.plupload.com/punbb/viewtopic.php?id=644

This is my code:

<script type="text/javascript">
    $(document).ready(function () {
        $(function () {
            $("#uploader").pluploadQueue({
                runtimes: 'flash,silverlight,html5,gears,browserplus',
                url: '/Home/Index',
                max_file_size: '10mb',
                unique_names: true,
                rename: true,
                resize: { width: 320, height: 330, quality: 90 },
                filters: [
                        { title: "Uploadable files", extensions: "jpeg,jpg,gif,png,zip,pdf,txt,rtf,doc,docx,xls,xlsx,csv" }
                    ],
                flash_swf_url: '/Assets/plupload/plupload.flash.swf',
                silverlight_xap_url: '/Assets/plupload/plupload.silverlight.xap',

                init: {
                    FilesAdded: function (objUploader, arrFiles) {
                        if (arrFiles.length > 0) {
                            $.each(arrFiles, function (i, file) {
                                file.name = "RENAME_" + file.name;
                            });
                        }

                        //objUploader.refresh();
                    },

                    UploadFile: function (objUploader, file) {
                        //file.name = "RENAME_" + file.name;
                    },

                    BeforeUpload: function (objUploader, file) {
                        //file.name = "RENAME_" + file.name;
                    }
                }
            });
            
            $('form').submit(function (e) {
                var uploader = $('#uploader').pluploadQueue();

                // Validate number of uploaded files
                if (uploader.total.uploaded == 0) {
                    // Files in queue upload them first
                    if (uploader.files.length > 0) {
                        // When all files are uploaded submit form
                        uploader.bind('UploadProgress', function () {
                            if (uploader.total.uploaded == uploader.files.length)
                                $('form').submit();
                        });

                        uploader.start();
                    } else
                        alert('You must at least upload one file.');

                    e.preventDefault();
                }
            });

        });
    });
</script>

What am I missing?

Re: Original file name remains after attempts to rename file in script

Unbeknownst to me, the setting "unique_names: true" was the problem. I changed it to "unique_names: false." In addition to this, I was looking at the actual file name that was coming across with the file object. The renamed value was represented in the request.form["name"] value.

Re: Original file name remains after attempts to rename file in script

jalban wrote:

Unbeknownst to me, the setting "unique_names: true" was the problem. I changed it to "unique_names: false." In addition to this, I was looking at the actual file name that was coming across with the file object. The renamed value was represented in the request.form["name"] value.

Jalban, can you post the working script ? I'm struggling with the same problem here. Thanks !

Re: Original file name remains after attempts to rename file in script

have you tried his code in the first post changing the unique_names setting to false as suggested in his second post?

Re: Original file name remains after attempts to rename file in script

Thats ok, i just found a way to do what i wanted. Using the files array directly instead of the arguments files object.

Like this:
$.each($('#uploader').pluploadQueue().files, function(){this.name = this.name.replace(/\'/g,' ')})

No link with OP question directly, but with what Jalban posted.

Re: Original file name remains after attempts to rename file in script

I like your post, but you could try to not only explain, but also show some examples how to do it?

Re: Original file name remains after attempts to rename file in script

I like your post, but you could try to not only explain, but also show some examples how to do it?

Re: Original file name remains after attempts to rename file in script

LeandroJF wrote:

have you tried his code in the first post changing the unique_names setting to false as suggested in his second post?

Hi, i´m new using plupload and i´m exciting never found susch a helpfull tool, but i´m looking for change the name of the files i upload, follow your instructions and i works, it really works in the screen, bt in the folder the name doesn´t change anything, can you help me?
I want to change the name of the file at the time it uploa in the destination folder....

S2

Camilo

Re: Original file name remains after attempts to rename file in script

@camilo.tabares.84, New file name is passed as a multipart argument - name. In PHP you can access it via $_REQUEST['name'].

If you want to see your issue fixed, do not report it here, do it on - GitHub.