<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic File upload using PHP curl post request. in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/File-upload-using-PHP-curl-post-request/m-p/295202#M27671</link>
    <description>&lt;P&gt;Hello.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using php curl to upload file here i have code.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;$url = "http://api.hubapi.com/filemanager/api/v2/files?hapikey=".$apikey;//change your api key here
      $realpath = '@'.$_FILES["file_select"]["tmp_name"].$_FILES["file_select"]["name"];
      $file_data= array('files[]'=&amp;gt;$realpath);
      $headers = array("Content-Type:multipart/form-data" ,  "hapikey: ".$apikey); // cURL headers for file uploading
      $postfields = array("files[]"=&amp;gt;$realpath,'file_names'=&amp;gt; $_FILES["file_select"]["name"]);
      

      $params = "--custom-boundary-123456789\r\n".
          "Content-Disposition: form-data; name=\"api\"\r\n\r\n".
          "static\r\n".
          "--custom-boundary-123456789\r\n".
          "Content-Disposition: form-data; name=\"files[]\"; filename=".$_FILES["file_select"]["name"]."\"\r\n".
          "Content-Type: text/html\r\n\r\n".
          "&amp;lt;div&amp;gt;Content for here here...&amp;lt;/div&amp;gt;\r\n".
          "--custom-boundary-123456789\r\n".
          "Content-Disposition: form-data; name=\"files[]\"; filename=".$_FILES["file_select"]["name"]."\"\r\n".
          "Content-Type: text/html\r\n\r\n".
          "&amp;lt;div&amp;gt;Content for file-b.html here...&amp;lt;/div&amp;gt;\r\n".
          "--custom-boundary-123456789--";

      $request_headers = array('Content-Type: multipart/form-data; boundary=----custom-boundary-123456789--');

      $ch = curl_init('http://api.hubapi.com/filemanager/api/v2/files?hapikey='.$apikey);
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
      curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);

      $reply = curl_exec($ch);
      $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
      curl_close($ch);



      echo $reply;&lt;/PRE&gt;&lt;P&gt;and&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;$url = "http://api.hubapi.com/filemanager/api/v2/files?hapikey=".$apikey;//change your api key here
      $realpath = '@'.$_FILES["file_select"]["tmp_name"].$_FILES["file_select"]["name"];
      $file_data= array('files[]'=&amp;gt;$realpath);
      $headers = array("Content-Type:multipart/form-data" ,  "hapikey: ".$apikey); // cURL headers for file uploading
      $postfields = array("files[]"=&amp;gt;$realpath,'file_names'=&amp;gt; $_FILES["file_select"]["name"]);

$ch = curl_init();
      
      @curl_setopt($ch, CURLOPT_POST, true);
      @curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($file_data));
      @curl_setopt($ch, CURLOPT_URL, $url);
      @curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
      
      @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);


      $response = @curl_exec($ch);
      $status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
      $curl_errors = curl_error($ch);
      @curl_close($ch);
      // echo "curl Errors: " . $curl_errors;
      // echo "\nStatus code: " . $status_code;
      // echo "\nResponse: " . $response;

      print_r($response);&lt;/PRE&gt;&lt;P&gt;Both response shows bad request.&lt;BR /&gt;what should i do?&lt;/P&gt;</description>
    <pubDate>Mon, 07 Oct 2019 12:51:36 GMT</pubDate>
    <dc:creator>kishan</dc:creator>
    <dc:date>2019-10-07T12:51:36Z</dc:date>
    <item>
      <title>File upload using PHP curl post request.</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/File-upload-using-PHP-curl-post-request/m-p/295202#M27671</link>
      <description>&lt;P&gt;Hello.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using php curl to upload file here i have code.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;$url = "http://api.hubapi.com/filemanager/api/v2/files?hapikey=".$apikey;//change your api key here
      $realpath = '@'.$_FILES["file_select"]["tmp_name"].$_FILES["file_select"]["name"];
      $file_data= array('files[]'=&amp;gt;$realpath);
      $headers = array("Content-Type:multipart/form-data" ,  "hapikey: ".$apikey); // cURL headers for file uploading
      $postfields = array("files[]"=&amp;gt;$realpath,'file_names'=&amp;gt; $_FILES["file_select"]["name"]);
      

      $params = "--custom-boundary-123456789\r\n".
          "Content-Disposition: form-data; name=\"api\"\r\n\r\n".
          "static\r\n".
          "--custom-boundary-123456789\r\n".
          "Content-Disposition: form-data; name=\"files[]\"; filename=".$_FILES["file_select"]["name"]."\"\r\n".
          "Content-Type: text/html\r\n\r\n".
          "&amp;lt;div&amp;gt;Content for here here...&amp;lt;/div&amp;gt;\r\n".
          "--custom-boundary-123456789\r\n".
          "Content-Disposition: form-data; name=\"files[]\"; filename=".$_FILES["file_select"]["name"]."\"\r\n".
          "Content-Type: text/html\r\n\r\n".
          "&amp;lt;div&amp;gt;Content for file-b.html here...&amp;lt;/div&amp;gt;\r\n".
          "--custom-boundary-123456789--";

      $request_headers = array('Content-Type: multipart/form-data; boundary=----custom-boundary-123456789--');

      $ch = curl_init('http://api.hubapi.com/filemanager/api/v2/files?hapikey='.$apikey);
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
      curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);

      $reply = curl_exec($ch);
      $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
      curl_close($ch);



      echo $reply;&lt;/PRE&gt;&lt;P&gt;and&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;$url = "http://api.hubapi.com/filemanager/api/v2/files?hapikey=".$apikey;//change your api key here
      $realpath = '@'.$_FILES["file_select"]["tmp_name"].$_FILES["file_select"]["name"];
      $file_data= array('files[]'=&amp;gt;$realpath);
      $headers = array("Content-Type:multipart/form-data" ,  "hapikey: ".$apikey); // cURL headers for file uploading
      $postfields = array("files[]"=&amp;gt;$realpath,'file_names'=&amp;gt; $_FILES["file_select"]["name"]);

$ch = curl_init();
      
      @curl_setopt($ch, CURLOPT_POST, true);
      @curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($file_data));
      @curl_setopt($ch, CURLOPT_URL, $url);
      @curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
      
      @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);


      $response = @curl_exec($ch);
      $status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
      $curl_errors = curl_error($ch);
      @curl_close($ch);
      // echo "curl Errors: " . $curl_errors;
      // echo "\nStatus code: " . $status_code;
      // echo "\nResponse: " . $response;

      print_r($response);&lt;/PRE&gt;&lt;P&gt;Both response shows bad request.&lt;BR /&gt;what should i do?&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 12:51:36 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/File-upload-using-PHP-curl-post-request/m-p/295202#M27671</guid>
      <dc:creator>kishan</dc:creator>
      <dc:date>2019-10-07T12:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: File upload using PHP curl post request.</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/File-upload-using-PHP-curl-post-request/m-p/295307#M27679</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/79694"&gt;@kishan&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not familiar enough with PHP to troubleshoot the code here; perhaps someone else in the community is more familiar with PHP? A quick search also returned a couple basic resources online; these may or may not be helpful to you:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://stackoverflow.com/questions/17862004/send-file-using-multipart-form-data-request-in-php" target="_blank"&gt;https://stackoverflow.com/questions/17862004/send-file-using-multipart-form-data-request-in-php&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://gist.github.com/maxivak/18fcac476a2f4ea02e5f80b303811d5f" target="_blank"&gt;https://gist.github.com/maxivak/18fcac476a2f4ea02e5f80b303811d5f&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regardless, can you provide more detail on the error response you're seeing from&amp;nbsp;HubSpot? Ideally, the status code &amp;amp; error message would be useful.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 20:33:32 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/File-upload-using-PHP-curl-post-request/m-p/295307#M27679</guid>
      <dc:creator>Derek_Gervais</dc:creator>
      <dc:date>2019-10-07T20:33:32Z</dc:date>
    </item>
  </channel>
</rss>

