Задать вопрос

Тел: +7 965 3737 888

581

Просмотров

1

Ответов

Fake File Uploads

In-browser testing frameworks (I'm using Windmill) have trouble testing file uploads because javascript's security policy prevents them from setting the value of file input fields. Instead the tests must issue some sort of "fake" file upload request, but implementing this on an ad-hoc basis quickly gets ugly.

This middleware is designed to support fake file uploads as transparently and as thoroughly as possible. For example, it is careful to properly trigger any file upload handlers so that things like upload progress reporting will work correctly. It can also simulate a slow file upload by sleeping between reads from the file.

From the client-side point of view, each input field of type "file" has a similarly-named hidden field automatically prepended. Test scripts can simply set the value of this hidden field to trigger a fake upload, rather than having to set the value of the file input field itself.

Вопрос полезен? Да0/Нет0
file_3236.py(11.2Кб)
None

Ответы (1):

Ответtoutanc:03.08.2009
Ответ полезен? Да0/Нет0

Hi,

I ran into trouble when I use non-ASCII characters:

If I use

FAKEUPLOAD_FILE_SPEC = {
    "NewPackage": { "filename": "test1.txt",  "contents": "I am a small text file."},
}

it works fine, however, if I use non ascii character like

FAKEUPLOAD_FILE_SPEC = {
    "NewPackage": { "filename": "test1.txt",  "contents": "€I am a small text file."},
}

I get that message:

File "~/Netvoyager/dev/volcano/dep/fakeupload/FakeFileUploadMiddleware.py", line 206, in read
    data = "".join(data)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128)

This also happens using a binary file if one byte is not ascii.

Obviously, this is a charset error, anybody got an idea on how to solve this?