<?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 Re: Upload string value to file - PHP in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Upload-string-value-to-file-PHP/m-p/713166#M31590</link>
    <description>&lt;P&gt;Yes, that worked! Thanks,&lt;/P&gt;</description>
    <pubDate>Tue, 12 Sep 2023 17:37:36 GMT</pubDate>
    <dc:creator>toki4004</dc:creator>
    <dc:date>2023-09-12T17:37:36Z</dc:date>
    <item>
      <title>Upload string value to file - PHP</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Upload-string-value-to-file-PHP/m-p/713103#M31588</link>
      <description>&lt;P&gt;I need to upload a simple string via api - there is no "file" on the server - the string will be generated in my PHP code. First, does it need to be in binary? Second, when I upload, I get a "1" written into a file - and thats it. How do I get that string uploaded? I don't get any errors back. Help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="php"&gt;$fields = array(
   "path" =&amp;gt; "/ba.txt",
   "autorename" =&amp;gt; false,
   "mode" =&amp;gt; "overwrite",
   "mute" =&amp;gt; false,
   "strict_conflict" =&amp;gt; false );

$string = 'hello there';
$binary = strigToBinary($string).PHP_EOL;

$headers = array(
   'Authorization: Bearer ' . $auth_token,
   'Content-Type: application/octet-stream',
   'Dropbox-API-Arg: '.json_encode($fields)
 );

$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, 'https://content.dropboxapi.com/2/files/upload');
curl_setopt($ch, CURLOPT_INFILE, $binary);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and here is my binary function&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="php"&gt;function strigToBinary($string) {
    $characters = str_split($string);
    $binary = [];
    foreach ($characters as $character) {
        $data = unpack('H*', $character);
        $binary[] = base_convert($data[1], 16, 2);
    }
    return implode(' ', $binary);    
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2023 09:29:31 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Upload-string-value-to-file-PHP/m-p/713103#M31588</guid>
      <dc:creator>toki4004</dc:creator>
      <dc:date>2023-09-14T09:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: Upload string value to file - PHP</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Upload-string-value-to-file-PHP/m-p/713120#M31589</link>
      <description>&lt;P&gt;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-upload" target="_blank"&gt;The /2/files/upload endpoint&lt;/A&gt; is a &lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#formats" target="_blank"&gt;"content-upload" style&lt;/A&gt; endpoint, meaning that it expects the raw bytes of the file data in the HTTPS request body (with corresponding "application/octet-stream" type, as you have).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Exactly how you retrieve that data and configure your HTTPS client to send it like that is up to you. Please note that we can't provide support for configuring third party clients themselves, as they're not made by Dropbox, so you may need to refer to the documentation for the client you're using for information on how to configure it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That said, looking at the code you shared, it looks like you might want to do the following, instead of your current 'CURLOPT_POSTFIELDS' and 'CURLOPT_INFILE' usage:&lt;/P&gt;
&lt;LI-CODE lang="php"&gt;curl_setopt($ch, CURLOPT_POSTFIELDS, $string);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2023 15:45:18 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Upload-string-value-to-file-PHP/m-p/713120#M31589</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2023-09-12T15:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: Upload string value to file - PHP</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Upload-string-value-to-file-PHP/m-p/713166#M31590</link>
      <description>&lt;P&gt;Yes, that worked! Thanks,&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2023 17:37:36 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Upload-string-value-to-file-PHP/m-p/713166#M31590</guid>
      <dc:creator>toki4004</dc:creator>
      <dc:date>2023-09-12T17:37:36Z</dc:date>
    </item>
  </channel>
</rss>

