我想使用php将一个大文件卷曲到Hoop。如果我执行正常的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);
箍上的文件将包含以下标题:
------------------------------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