Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encoding of non-ascii file names

Tags:

dropzone.js

For uploads with drop zone.js, file names containing non-ascii characters will not be encoded before sent to the server. They are just left as they are:

------WebKitFormBoundaryvXgdeNXSwHZBUrFJ
Content-Disposition: form-data; name="file[0]"; filename="täst.png"

As a result, on server-side encoding is unknown.

Is there a way to force dropzone.js to UrlEncode the filename, similar to RFC 6266?

Content-Disposition: form-data; name="file[0]"; filename*=utf-8''t%c3%a4st.png

Or is there any other solution?

like image 618
Paul Avatar asked Sep 06 '15 14:09

Paul


People also ask

What is an example of a non-ASCII character?

An example of a non-ASCII character is the Ñ. The URL can't contain any non-ASCII character or even a space.


1 Answers

I ran into the same problem and what I ended up doing to solve this was to pass an additional parameter.

$("#myDz").dropzone({
    init: function () {
        this.on("sending", function(file, xhr, formData) {
            var fn = encodeURI(file.name)
            formData.append("encFilename", fn);
        });
    }
});

This will send the additional parameter encFilename to the backend which can then be used to name the file when it's written to disk. file.name can't be updated at that point but doing it like this works just fine.

like image 180
IamNaN Avatar answered Jan 01 '23 08:01

IamNaN