Post

2 followers Follow
0
Avatar

PodioFile::get just echoes 1 and exits script

I'm uploading files with

PodioFile::upload($filePath,$fileName)

which works fine and returns your ID.

Immediately after this I call

PodioFile::get($podio_id);

to get the size of the file and compare the size with the local file to make sure it was uploaded ok. (I had issues in the past where files got partially uploaded and your system still returned a valid id; comparing file size seems to does this check.)

So, when I run

PodioFile::get($podio_id);

echo 'File data';

my script simply echoes 1 and exits. This should come from the library as the echo in my script ("File data") is not shown. Do you have an idea what might be causing this?

Thanks!

Kalin Sivov Answered

Please sign in to leave a comment.

6 comments

0
Avatar

Hi Andreas,

here's the result of the debugged code.

Podio::$debug = true;

    try {

              $action = PodioFile::get($podio_id);

            }

            catch(PodioError $e) {

              print_r($e);

              print "\nstatus: ".$e->status;

              print "\nurl: ".$e->url;

              print "\nerror_description: ".$e->body['error_description'];

              die(print_r("\nbody: ".$e->body));

            }

ERR:

status: 400

url: /file/27775424

error_description:

body: 1

LOGGED RESPONSE:

2013-01-15 11:14:56 400 GET /file/27775283

2013-01-15 11:14:56 Reponse: <html>

<head><title>400 Bad Request</title></head>

<body bgcolor="white">

<center><h1>400 Bad Request</h1></center>

<hr><center>nginx/1.0.14</center>

</body>

</html>

2013-01-15 11:14:57 Performed 1 requests in 0.153859 seconds

 

THE COMPLETE ERR OBJECT

 

PodioBadRequestError Object

(

    [body] =>

    [status] => 400

    [url] => /file/27775424

    [message:protected] =>

    [string:Exception:private] =>

    [code:protected] => 0

    [file:protected] => .../lib/PodioAPI.php

    [line:protected] => 190

    [trace:Exception:private] => Array

        (

            [0] => Array

                (

                    [file] => .../lib/PodioAPI.php

                    [line] => 250

                    [function] => request

                    [class] => Podio

                    [type] => ::

                    [args] => Array

                        (

                            [0] => GET

                            [1] => /file/27775424

                            [2] => Array

                                (

                                )

                        )

                )

            [1] => Array

                (

                    [file] => .../models/PodioFile.php

                    [line] => 38

                    [function] => get

                    [class] => Podio

                    [type] => ::

                    [args] => Array

                        (

                            [0] => /file/27775424

                        )

                )

            [2] => Array

                (

                    [file] => script.php

                    [line] => 526

                    [function] => get

                    [class] => PodioFile

                    [type] => ::

                    [args] => Array

                        (

                            [0] => 27775424

                        )

                )

            [3] => Array

                (

                    [file] => script.php

                    [line] => 1076

                    [function] => fileIsOK

                    [args] => Array

                        (

                            [0] => 27775424

                            [1] => N5jCVKy4Sd-6yVrDxkXvm-B0N8iTY0MS-idCSCuzFpY

                        )

                )

            [4] => Array

                (

                    [file] => script.php

                    [line] => 405

                    [function] => doFiles

                    [args] => Array

                        (

                        )

                )

        )

    [previous:Exception:private] =>

)

So it is a Bad Request but I cannot understand what I am missing. I'm passing just a podio_id here ..

Kalin Sivov 0 votes
0
Avatar

Hi Kalin,

You are getting the error because you are trying to get a file before it has been attached to something. If you run PodioFile::get() after you have created your item/task/status/whatever it will work.

However, you don't need to do any of that. PodioFile::upload() returns a full file object. If you just need the file size all you need to do is:

$file = PodioFile::upload($path, $name);

print $file->size; 

Andreas Haugstrup Pedersen 0 votes