2017년 5월 6일 토요일

Piwigo - how to add photos with App Inventor


Hi, i'm implementing a Piwigo image server and i would like to upload photos from my app.

This is what  Piwigo says about "simple upload":
This method requires authentication with an administrator user.
This method requires an HTTP POST request.
Important note: we are uploading a file, so the HTTP request encoding must be set to “form-data”.

and the code

#!/usr/bin/perl
use LWP::UserAgent;
my %conf = (
    base_url => 'http://piwigo.org/demo',
);
my $ua = LWP::UserAgent->new;
$ua->cookie_jar({});
$ua->post(
    $conf{base_url}.'/ws.php',
    {
        method => 'pwg.session.login',
        username => 'john',
        password => 'NWgeWHjy8',
    }
);
$ua->post(
    $conf{base_url}.'/ws.php',
    {
        method => 'pwg.images.addSimple',
        image => ['/home/john/photos/wild tiger.jpg'],
        category => 4,
        tags => 'tag1, tag2, another tag',
        name => 'A nice title',
        comment => 'A longer description',
        author => 'Paul Nikanon',
        level => 2,
    },
    'Content_Type' => 'form-data',
);

I have tried to use Web component in different ways to login and upload but i have failed :-/

Can anyone help me?

--
any link to the API documentation?
what did you try? 

It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

-- 
Link to API documentation : http://piwigo.org/demo/tools/ws.htm

What i have done as attachment.

I log correctly and it says:

<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
1
</rsp>

and that it's ok ... i think i have to pass that "1" in some unknown way :)

After Web2 it responds:

<?xml version="1.0"?>
<rsp stat="fail">
 <err code="401" msg="Access denied" />
</rsp> 

Thank you in advance!

-- 


 so the HTTP request encoding must be set to “form-data”.

I don't know, if this is possible?

In App Inventor you only can use the PostFIle method to upload files to somewhere...
btw. where is your file you like to upload? I only can see some text you are sending...

see the following examples, which work fine
How to upload a file into your Dropbox






PostFile(text path)
Performs an HTTP POST request using the Url property and data from the specified file.
If the SaveResponse property is true, the response will be saved in a file and the GotFile event will be triggered. The ResponseFileName property can be used to specify the name of the file.
If the SaveResponse property is false, the GotText event will be triggered.

-- 


btw. where is your file you like to upload?

When i pick an image from gallery i set it as variable "nome_foto" (dont know if this is the right way)

Here you can get some idea maybe :

http://piwigo.org/forum/viewtopic.php?id=22089
and

You need to get the cookies sent with the response to your login request and send it in subsequent requests

but when i read response content after the login i see no text/cookie 

-- 
yes, your variable nome_foto is the path to your image, but not the image itself...
here is some more documentation http://piwigo.org/doc/doku.php?id=dev:webapi:pwg.images.addsimple

I don't think you can use content-type "form-data" in App Inventor, I might be wrong...
probably @Evan can help?

-- 
Just thinking about the problem ... maybe i can collect data (title, description, image) as usual and then pass the data to webviewer and write the code in php?

Do you think i can work this way?

-- 
the webviewer of App Inventor can't upload images, but the webviewer of Thunkable can, see also here

-- 
:( Always problems :(

-- 
Hey Taifun, just bought your ftp extension 8)

Pleaseeee send me as soon as you can so i can work on app :)

Thank you in advance!

-- 
just sent! Than you!

-- 
Great :)

I will add here what i'm trying !

-- 
hi Taifun, i go offtopic for a while ... while working on uploading photo to piwigo application i try to upload by ftp the image to the server.
Login and password are ok, app says successfully uploaded but i find no image on server ... do you have any idea?

-- 
update!

i have found the problem .. i was uploading to /immagini/ instead of /www.mysitename.com/immagini/

It says successfull anyway even if image is not there (1st try)

-- 
hi Taifun ... there's an error sometimes with ftp extension.
Attached the error

-- 
How to avoid runtime errors with the companion app
1. After importing an extension, please restart the companion app.
2. If you like to use an extension on a different screen, in Screen1 additionally drag the extension into the working area.

While starting the companion app, all necessary assets and also the imported extensions of your project will be copied to your device. So in case the no such class error shows up, the extension code to run the extension is not available on your device. Without that code the companion app is not able to execute methods from the extension.

In case restarting the companion app does not work for you after trying several times, then as it looks like the only way for you to test you app will be after building it using the apk file.       

-- 


댓글 없음:

댓글 쓰기