我想用php把一个大文件 curl 成圈。如果我上传一个普通的php文件,文件前面会有一些头文件。
当我尝试这个:
$url = http://hoop:14000/filename?op=create&user.name=root
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => "@" . $this->filepath));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/octet-stream', 'Expect:'));
$content = curl_exec($ch);
hoop上的文件将包含以下标题:
------------------------------f0f063939ed8
Content-Disposition: form-data; name="file"; filename="phpbsA4ty"
Content-Type: application/octet-stream
{binary data here........}
我猜应该是原始的后期数据。所以我可以让它这样工作:
$url = http://hoop:14000/filename?op=create&user.name=root
$fileData = file_get_contents($this->filepath);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fileData);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/octet-stream', 'Expect:'));
$content = curl_exec($ch);
但大文件会导致内存错误:
PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 8388608 bytes)
有没有一种方法可以在不将文件加载到内存的情况下发布原始文件?
我可以使用hoop文档中的说明在命令行上完成
curl -X POST -c ~/.hoopauth "http://<HOOP_HOST>:14000/<PATH>?op=create[&<OPTION>]*" \ --data-binary @data.txt --header "content-type: application/octet-stream"
从http://cloudera.github.com/hoop/docs/latest/httprestapi.html
暂无答案!
目前还没有任何答案,快来回答吧!