Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary file support for multipart/form-data #189

Open
zostay opened this issue Mar 13, 2018 · 0 comments
Open

Binary file support for multipart/form-data #189

zostay opened this issue Mar 13, 2018 · 0 comments

Comments

@zostay
Copy link

zostay commented Mar 13, 2018

I happily discovered that the multipart/form-data handling here is close to what you can do with LWP in Perl. However, while something like this will work fine:

my $req = POST('http://localhost/', content => [a => '1', b => ['META6.json']], Content-type => 'multipart/form-data');
my $res = $ua.request($req);

This will not:

my $req = POST('http://localhost/', content => [a => '1', b => ['backups.tar.gz']], Content-type => 'multipart/form-data');
my $res = $ua.request($req);

The exception is:

Malformed UTF-8 at line 1 col 2
in block at /usr/local/Cellar/rakudo-star/2018.01/share/perl6/site/sources/C1F4E39233DAF4BE7A977583897637177143784D (HTTP::Request) line 220
in method form-data at /usr/local/Cellar/rakudo-star/2018.01/share/perl6/site/sources/C1F4E39233DAF4BE7A977583897637177143784D (HTTP::Request) line 199
in block at /usr/local/Cellar/rakudo-star/2018.01/share/perl6/site/sources/C1F4E39233DAF4BE7A977583897637177143784D (HTTP::Request) line 183
in method add-form-data at /usr/local/Cellar/rakudo-star/2018.01/share/perl6/site/sources/C1F4E39233DAF4BE7A977583897637177143784D (HTTP::Request) line 169
in sub POST at /usr/local/Cellar/rakudo-star/2018.01/share/perl6/site/sources/8C3E66EA3422F50B53B12301D43EDC5DCB9BE169 (HTTP::Request::Common) line 24
in sub POST at /usr/local/Cellar/rakudo-star/2018.01/share/perl6/site/sources/8C3E66EA3422F50B53B12301D43EDC5DCB9BE169 (HTTP::Request::Common) line 28
in block at /Users/sterling/test.p6 line 1

The problem is that the file is being slurped as text, when there's no way of knowing what the format of the original file is. The slurping ought to be done in bin mode, but that will lead to "Cannot use a Buf as a string, but you called the Stringy method on it" as soon as the binary content is added to the otherwise stringy content used to construct the headers and multipart boundaries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant