Discussion:
Postman 2 Mojo
(too old to reply)
Pierre Pannetier
2016-09-30 08:51:20 UTC
Permalink
<Loading Image...>

Hi

I'm trying to post 2 files to an API build with Mojo, testing it with
Postman

Well doing this, the only way i found to get files content is to split
$string with regular expressions

my $asset = $self->req->content->asset;
my $string=$asset->slurp;


I tried Mojo::Upload; without success.

Anybody could drive me to get each file content without playing with
regular expressions ?

Many thx.
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Juergen Nickelsen
2016-09-30 09:59:43 UTC
Permalink
Post by Pierre Pannetier
Well doing this, the only way i found to get files content is to split
$string with regular expressions
my$asset =$self->req->content->asset;
my$string=$asset->slurp;
I tried Mojo::Upload; without success.
Anybody could drive me to get each file content without playing with
regular expressions ?
To make sure I understand you correctly: Do you have the byte stream of
the file in $string as a single string, as using
Mojo::Asset::Memory::slurp() would suggest?

If so, splitting it on line ends to get an array of lines as in

@lines = split(/\n/, $string);

is indeed the way this is meant to be done (and not really what I'd call
playing with regexps).

Regards, Juergen.
--
<***@fu-berlin.de> Tel +49.30.838-50740 Fax -450740
Zentraleinrichtung fuer Datenverarbeitung, Systems Impetulant
Freie Universitaet Berlin, Fabeckstrasse 32, 14195 Berlin, DE
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Pierre Pannetier
2016-09-30 12:39:33 UTC
Permalink
Actually this what i have from the $asset->slurp;

------WebKitFormBoundary2jXzI9WLBRoANocy
Content-Disposition: form-data; name="text"; filename="test.json"
Content-Type: application/octet-stream

{
JSON
}
------WebKitFormBoundary2jXzI9WLBRoANocy
Content-Disposition: form-data; name="filepdf"; filename="test(2).PDF"
Content-Type: application/pdf

%PDF-1.4
...pdf data....
%%EOF

So in the case i have to split et manage to get the files content using
regexps.

But i'm wondering it is possible to get this through something like

my $pdfdata = $self->param('filepdf');
my $jsondata = $self->param('text');
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Brian Manning
2016-09-30 15:02:30 UTC
Permalink
Post by Pierre Pannetier
But i'm wondering it is possible to get this through something like
my $pdfdata = $self->param('filepdf');
my $jsondata = $self->param('text');
The "param" method of your Mojolicious::Controller object should work [1]
for accessing your POSTed files, but you can also try retrieving the files
directly from the Mojo::Message object [2] inside your controller;

# assuming '$self' isa Mojolicious::Controller object...
my $pdfdata = $self->req->upload('filepdf');
my $jsondata = $self->req->upload('text');

The above syntax is working for me uploading single files from iOS
(NSURLConnection) into Mojolicious. There's also a small mention of
uploads in the Mojolicious Tutorial [3].

Thanks,

Brian

[1] https://metacpan.org/pod/Mojolicious::Controller#param
[2] https://metacpan.org/pod/Mojo::Message#upload
[3] https://metacpan.org/pod/distribution/Mojolicious/lib/Mojolicious/Guides/Tutorial.pod#File-uploads
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Pierre Pannetier
2016-10-03 10:20:29 UTC
Permalink
Hi Brian ,

Thanks for your answer, i tried it, but this returns empty values for me.


my $pdfdata = $self->req->upload('filepdf');
my $jsondata = $self->req->upload('text');
print "JSONDATA:".$jsondata."\n";
print "PDFDATA:".$pdfdata."\n";

Use of uninitialized value $jsondata in concatenation (.) or string at ./
test.pl line 645.
JSONDATA:
Use of uninitialized value $pdfdata in concatenation (.) or string at ./test
.pl line 646.
PDFDATA:

I'm still wondering why...
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Brian Manning
2016-10-03 13:36:52 UTC
Permalink
Post by Pierre Pannetier
Hi Brian ,
Thanks for your answer, i tried it, but this returns empty values for me.
I'm still wondering why...
Maybe create a small demo Mojolicious::Lite app that demonstrates your
problem, so that others can test it with Postman as well?

FWIW, it took me a while to format the POST message correctly before
Mojolicious would decode it.

Thanks,

Brian
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Loading...