Discussion:
UserAgent: Posting Mojo::Asset::Memory?
(too old to reply)
rasta
2014-08-29 14:33:53 UTC
Permalink
Hi guys!

I'm getting a file from the client which I then need to forward to another
server.

my $file = $self->req->upload('file');

But if the file is small enough, it's just in memory...

if($file->asset->is_file){
$post = $ua->post($url => { 'Content-Type' => $mimetype } => form => {
file => { file => $file->asset->path }} );
}else{
what should I do here???
}

Do I have to mess with creating a temp file first? Or can I feed the user
agent with the asset somehow?

Thanks!
Rasta
--
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 http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Александр Грошев
2014-08-29 14:46:10 UTC
Permalink
$file = $self->req->upload('file')->asset(Mojo::Asset::File->new);

And all assets will be stored to files.
Post by rasta
Hi guys!
I'm getting a file from the client which I then need to forward to another
server.
my $file = $self->req->upload('file');
But if the file is small enough, it's just in memory...
if($file->asset->is_file){
$post = $ua->post($url => { 'Content-Type' => $mimetype } => form => {
file => { file => $file->asset->path }} );
}else{
what should I do here???
}
Do I have to mess with creating a temp file first? Or can I feed the user
agent with the asset somehow?
Thanks!
Rasta
--
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
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
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 http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
rasta
2014-08-29 20:29:42 UTC
Permalink
But if I do this, the $file (Mojo::Upload) seems to contain an empty asset,
as if it rewrites what was there.

my $upload = $self->req->upload('file')->asset(Mojo::Asset::File->new);

$self->app->log->debug($self->app->dumper($upload->asset));

--->

[Fri Aug 29 22:15:09 2014] [debug] bless( {}, 'Mojo::Asset::File' )
Post by Александр Грошев
$file = $self->req->upload('file')->asset(Mojo::Asset::File->new);
And all assets will be stored to files.
--
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 http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Александр Грошев
2014-08-29 20:39:39 UTC
Permalink
Strange. It works for me.
Try to use $upload->move_to().

use File::Temp 'tempfile';
...
} else {
my $tfile = File::Temp->new;
$file->move_to($tfile->filename);
$post = $ua->post($url => { 'Content-Type' => $mimetype } => form => { file
=> { file => $tfile->filename }} );
}
Post by rasta
But if I do this, the $file (Mojo::Upload) seems to contain an empty
asset, as if it rewrites what was there.
my $upload = $self->req->upload('file')->asset(Mojo::Asset::File->new);
$self->app->log->debug($self->app->dumper($upload->asset));
--->
[Fri Aug 29 22:15:09 2014] [debug] bless( {}, 'Mojo::Asset::File' )
Post by Александр Грошев
$file = $self->req->upload('file')->asset(Mojo::Asset::File->new);
And all assets will be stored to files.
--
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
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
С уважеМОеЌ, АлексаМЎр ГрПшев.
--
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 http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
rasta
2014-08-30 08:37:47 UTC
Permalink
Works like a charm! Thanks Alex!!
Post by Александр Грошев
Strange. It works for me.
Try to use $upload->move_to().
use File::Temp 'tempfile';
...
} else {
my $tfile = File::Temp->new;
$file->move_to($tfile->filename);
$post = $ua->post($url => { 'Content-Type' => $mimetype } => form => {
file => { file => $tfile->filename }} );
}
Post by rasta
But if I do this, the $file (Mojo::Upload) seems to contain an empty
asset, as if it rewrites what was there.
my $upload = $self->req->upload('file')->asset(Mojo::Asset::File->new);
$self->app->log->debug($self->app->dumper($upload->asset));
--->
[Fri Aug 29 22:15:09 2014] [debug] bless( {}, 'Mojo::Asset::File' )
Post by Александр Грошев
$file = $self->req->upload('file')->asset(Mojo::Asset::File->new);
And all assets will be stored to files.
--
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
<javascript:>.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
С уважеМОеЌ, АлексаМЎр ГрПшев.
--
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 http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
sri
2014-08-29 17:08:47 UTC
Permalink
Post by rasta
Do I have to mess with creating a temp file first? Or can I feed the user
agent with the asset somehow?
No. Yes.

--
sebastian
--
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 http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
rasta
2014-08-29 20:29:54 UTC
Permalink
Example. Please.
Post by rasta
Do I have to mess with creating a temp file first? Or can I feed the user
Post by rasta
agent with the asset somehow?
No. Yes.
--
sebastian
--
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 http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
sri
2014-08-29 20:39:47 UTC
Permalink
Post by rasta
Example. Please.
Where in the documentation have you looked and not found anything?

--
sebastian
--
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 http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
rasta
2014-08-30 08:38:14 UTC
Permalink
Looked here:
http://mojolicio.us/perldoc/Mojo/Upload
http://mojolicio.us/perldoc/Mojo/Asset/Memory
http://mojolicio.us/perldoc/Mojo/Asset/File
http://mojolicio.us/perldoc/Mojo/UserAgent
http://mojolicio.us/perldoc/Mojolicious/Guides/Cookbook#Large-file-upload

Not found a way how to start a file upload using memory asset.
Post by rasta
Example. Please.
Where in the documentation have you looked and not found anything?
--
sebastian
--
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 http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
sri
2014-08-30 12:58:46 UTC
Permalink
Looked here:...
If you look at the description of the actual method you are using and the
resources it links to, you still can't figure it out?

http://mojolicio.us/perldoc/Mojo/UserAgent#post

--
sebastian
--
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 http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
rasta
2014-08-30 16:44:04 UTC
Permalink
OK you've got your frag man! (:

This is the part <http://mojolicio.us/perldoc/Mojo/UserAgent/Transactor#tx>,
if anyone will be interested:

# POST request with upload streamed from assetmy $asset = Mojo::Asset::Memory->new->add_chunk('lalala');my $tx = $t->tx(
POST => 'http://example.com' => form => {mytext => {file => $asset}});


So I only have to do

$post = $ua->post($url => { 'Content-Type' => $mimetype } => form => { file
=> { file => $upload->asset }} );

without the need to check whether the asset is a file or not.
Looked here:...
If you look at the description of the actual method you are using and the
resources it links to, you still can't figure it out?
http://mojolicio.us/perldoc/Mojo/UserAgent#post
--
sebastian
--
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 http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
sri
2014-08-30 23:39:50 UTC
Permalink
I'm usually giving hints instead of direct answers to find weaknesses in
the documentation. ;)

--
sebastian
--
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 http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...