【问题标题】:PHP CURL PUT from Amazon S3 stream wrapper (tcp stream)来自 Amazon S3 流包装器的 PHP CURL PUT(tcp 流)
【发布时间】:2017-07-29 13:43:19
【问题描述】:

我正在尝试 (PHP) 使用 S3 流包装器 (s3://...) 将文件从 Amazon S3 卷曲到 Vimeo 并收到以下错误:

curl_setopt_array(): 不能将 tcp_socket/ssl 类型的流表示为 [...] 中的 STDIO 文件

有没有办法 cURL PUT 一个远程文件?这是正在发送的 curl 选项:

$curl_opts = array(
  CURLOPT_PUT => true,
  CURLOPT_INFILE => $file, // this refers to 's3://path-to-object'
  CURLOPT_INFILESIZE => $size,
  CURLOPT_UPLOAD => true,
  CURLOPT_HTTPHEADER => array('Expect: ', 'Content-Range: replaced...')
);

【问题讨论】:

    标签: php curl amazon-s3 vimeo-api php-stream-wrappers


    【解决方案1】:

    在 PUT 之前将文件保存到本地服务器:

    $file = tempnam(sys_get_temp_dir(), "foo");
    $data = file_get_contents("s3://path-to-object");
    $size = strlen($data);
    file_put_contents($file, $data);
    $curl_opts = array(
      CURLOPT_PUT => true,
      CURLOPT_INFILE => $file, // this refers to 's3://path-to-object'
      CURLOPT_INFILESIZE => $size,
      CURLOPT_UPLOAD => true,
      CURLOPT_HTTPHEADER => array('Expect: ', 'Content-Range: replaced...')
    );
    

    【讨论】:

    • 这是我目前的解决方法,但我正在尝试绕过该下载步骤。谢谢!
    • 我猜一些应用程序需要使数据流动,所以到目前为止没有下载文件我看不到解决方案
    • 当你 PUT 时,你正在上传一个具体的对象。数据流不是那样的。它没有有限的大小。
    猜你喜欢
    • 2017-06-01
    • 1970-01-01
    • 2010-12-02
    • 1970-01-01
    • 2012-05-06
    • 1970-01-01
    • 1970-01-01
    • 2020-10-21
    • 1970-01-01
    相关资源
    最近更新 更多