Re: XMLRPC Binary Transfer
Gaetano Giunta <[email protected]> Thu, 22 Jan 2009 10:34:23 +0100
| Newsgroups | gmane.comp.php.xml-rpc |
|---|---|
| Message-ID | <[email protected]> |
Frank H a =E9crit :
> Hi all,
>
> I am trying to create a function that allows me to send binary files =
> from a client and have the server write it into a directory.
> I have it working right now, but it errors when I try to send a file =
> greater then about 300 Kb. Any file under that size will
> transfer just fine.
>
> Here is the function I have on the server...
>
> function upload_file2($m)
> {
> $param1 =3D $m->getParam(0);
> $write_file =3D $param1->scalarval();
> $convert_file =3D fopen($write_file, "rb");
>
> $param2 =3D $m->getParam(1);
> $file_name =3D $param2->scalarval();
>
> $test_write =3D fopen("/tmp/".$file_name, "w");
> fwrite($test_write, $write_file);
> fclose($test_write);
>
> return new xmlrpcresp(new xmlrpcval($file_name));
> }
>
> $upload_file2_sig =3D array(array($xmlrpcBase64,$xmlrpcBase64, =
> $xmlrpcString));
> $upload_file2_doc =3D 'uploads a binary file';
Apart from the fact that:
- I cannot understand the intended meaning of the line $convert_file =3D =
fopen($write_file, "rb");
- I hope you trust the source of webservice calls, as you're not =
validating $file_name for the presence of .. (or other similar escape) =
sequences
- you could test the result of fopen before doing fwrite+fclose
- the function signature should read =
array(array($xmlrpcString,$xmlrpcBase64, $xmlrpcString));
- you could probably return the numbers of bytes written instead of the =
filename
it looks fine.
>
> I am using a Python client to send the file. I was playing around =
> with a Python server to transfer files and the Python
> server does not run into any problems with file size.
>
> This is what I have on the python client...
>
> import xmlrpclib
>
> print("Trying to connect...")
> server_url =3D 'http://some_url/new_server.php';
> server =3D xmlrpclib.Server(server_url);
>
> handle =3D open("nova.bmp")
> file_name =3D "fetch_nova.bmp"
> send_file =3D server.sendFile(xmlrpclib.Binary(handle.read()), file_name)
>
>
> This is the error I get when trying to use the Python Client/Php =
> Server combo
>
> Trying to connect...
> Traceback (most recent call last):
> File "testProc_client.py", line 20, in ?
> send_file =3D server.sendFile(xmlrpclib.Binary(handle.read()), =
> file_name)
> File "/usr/lib/python2.3/xmlrpclib.py", line 1029, in __call__
> return self.__send(self.__name, args)
> File "/usr/lib/python2.3/xmlrpclib.py", line 1316, in __request
> verbose=3Dself.__verbose
> File "/usr/lib/python2.3/xmlrpclib.py", line 1070, in request
> headers
> xmlrpclib.ProtocolError: <ProtocolError for =
> mmodev.jpl.nasa.gov/frank/xmlrpc/demo/server/new_server.php: -1 >
Sorry, but the Python error does not help that much.
You should:
- check the php error log on the server for any hint
- check memory_limit, max_execution_time and especially post_max_size =
php.ini directives
- enable debug mode on the php server object
bye
Gaetano