hello Dan
 
Good day.
 Yea, i looked at the docs of Mojo::UserAgent again and found the 
following. Tried it and it works.


my $tx = $ua->build_tx(PUT => 'http://example.com' => {Accept => '*/*'} => 
'Content!');


 And given i had user info credentials , I instantiated a Mojo::URL object 
with the userinfo() set with the credentials and it worked.

 Here's a test script to share:

*#!/usr/bin/env perl*

*use *Mojolicious::Lite;

*use *Mojo::UserAgent;

*use *Mojo::URL;

*my* *$ua*  = Mojo::UserAgent->new;


    *my* *$url* = Mojo::URL->new(
*'http://127.0.0.1:9211/file_storage/stone_free.txt'*)->userinfo(
*'dconway:IsperlRoyalty'*);

    *my* *$res*        = *$ua->put*( *$url*  => {*Accept* => *'*/*'*} =>  
Mojo::File->new(*'/Users/hendrix/test-file.txt'*)->slurp  );







On Thursday, 16 July 2020 at 12:20:17 UTC+10 gri...@gmail.com wrote:

> The URL you are PUTting to does not appear to expect a form, but raw 
> content, so you will not want to use the "form" generator. You can pass raw 
> content as a bare argument like so:
>
> $self->ua->put_p($url, $file_object->asset->slurp);
>
> You will probably also want to set a Content-Type header for the MIME type 
> of the file contents. This would be set by a hash between the URL and 
> content, there are some examples in 
> https://metacpan.org/pod/Mojo::UserAgent#SYNOPSIS.
>
> -Dan
>
> On Wed, Jul 15, 2020 at 10:00 PM Gordon Dollarnanda <anex...@gmail.com> 
> wrote:
>
>>
>> hi guys,
>>
>>   Just started on a project with Mojolicious.
>>
>> Task: to upload a file into mojo and then issue a PUT command to transfer 
>> that file to a file server.
>>
>> I have been struggling to find documentation on using put_p/put in terms 
>> of the parameters for the syntax.
>>
>> Often, looking at https://mojolicious.org/perldoc/Mojo/UserAgent#put_p, 
>> it is too brief and not concise.
>>  I have also tried to look for the source code in the Mojolicious 
>> framework which does the actual put_p/put to no avail. I had looked up the 
>> source of Mojo <https://mojolicious.org/perldoc/Mojo> :: UserAgen 
>> <https://mojolicious.org/perldoc/Mojo/UserAgent>t and the packages it is 
>> "use"-ing also to no avail.
>>
>> --------
>>    $self->ua->put_p(
>>             
>>            # my_target_url_object is a Mojo::URL with the
>>            # user info and actual url of the
>>            # file server defined.
>>
>>            # $file_object is a Mojo::File::Asset representing a file I 
>> had uploaded from my local machine
>>
>> *            $my_target_url_object => form => {*
>>
>> *                'content' => 
>> $file_object->asset->{'content'},            }*
>>         )->then(
>>         sub ($tx) {
>>             return $self->parse_response_p($tx);
>>         }
>>     )->catch(
>>         sub($error) {
>>             p->reject("Connection error: $error");
>>         }
>>     );
>> -----------
>> When I use the put call above,  the content of my input file becomes 
>> "content=+Why+Georgia%3F%0A" instead of just "Why Georgia" (which was what 
>> I had uploaded earlier).
>> I must be doing something wrong.
>>
>>  I have since tried many variations  to the call to put_p to no avail.
>> Sometimes, if i do not provide the hash key, 'content', the actual cost 
>> when i cat the file in the target webserver directory would be literally 
>> 'HASH%3234234234';
>>
>> Can any one please point me to proper documentation clearly describing 
>> how to execute a put/put_p in a  Mojolicious controller?
>>
>> Thank you, guys
>>
>>
>> Gordon 
>>
>>
>>
>>
>>
>> -- 
>> 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 view this discussion on the web visit 
>> https://groups.google.com/d/msgid/mojolicious/19d370c9-81e3-4a52-aac9-254eef693bb8n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/mojolicious/19d370c9-81e3-4a52-aac9-254eef693bb8n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/21fba0c4-8852-490a-8073-b37aa55f57dcn%40googlegroups.com.

Reply via email to