Zend Http Client SetFileUpload with File Handle Argument

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Zend Http Client SetFileUpload with File Handle Argument

richard
This post has NOT been accepted by the mailing list yet.
Hello all.

The current Zend\Http\Client setFileUpload method will result in file_get_content( filepath ) which is appended to a request body string.

The problem is that reading a file into a string limits the size of a file upload to the amount of ram available / configured. 

For my use case I am uploading a file to a webserver and then using the http client to transfer the file to a media service alongside REST style post arguments, (to resize etc).

I have modified the http client class to allow passing in a file handle. 

I want to get setFileUpload file handle functionality into the library. 

Method definition,
public function setFileUpload($filename, $formname, $data = null, $ctype = null)

$filename = '/tmp/foo';
$formname = 'blah[]' ;

Normal Usage
$client->setFileUpload($filename, $formname )

FileHandle Usage
setFileUpload($filename, $formname, fopen($filename), mime_content_type($filename) )

I have kept the method definition the same (though more loosely typed) to prevent api changes.

I have changed $client->prepareBody() to return an array or string depending on whether iterating files contains a handle or not.

The other minor changes involve recursing the body array for content length, and in the socket adapter to write to the socket.

Is there any point attempting to get a pull request accepted for this ?