<?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 Hhow upload a file using c# and a file stream? in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Hhow-upload-a-file-using-c-and-a-file-stream/m-p/904795#M70289</link>
    <description>&lt;P&gt;Hello everyone, I am trying to send pdf files to hubspot but the new api asks for a url as a parameter and I do not want to save the file in my application but save it directly in hubspot. The old version of the api does allow you to do this but it asks me to enable a scope ("file-manager-access") that seems to no longer be present with the new authentication. How can I send my files using bytes instead of a URL?&lt;BR /&gt;&lt;BR /&gt;reference urls:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://legacydocs.hubspot.com/docs/methods/files/v3/upload_new_file" target="_blank"&gt;https://legacydocs.hubspot.com/docs/methods/files/v3/upload_new_file&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://developers.hubspot.com/docs/api/files/files" target="_blank"&gt;https://developers.hubspot.com/docs/api/files/files&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;my code:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt; public async Task UploadFile2(string id, Stream stream) {

     static byte[] ConvertStreamToBytes(Stream streamData)
     {
         using (MemoryStream memoryStream = new MemoryStream())
         {
             streamData.CopyTo(memoryStream);
             return memoryStream.ToArray();
         }
     }

     byte[] file = ConvertStreamToBytes(stream);

     var options = new RestClientOptions("https://api.hubapi.com")
     {
         MaxTimeout = -1,
     };
     var client = new RestClient(options);
     var request = new RestRequest("/filemanager/api/v3/files/upload", Method.Post);
     request.AddHeader("Authorization", "Bearer my-bearer-token");
     request.AlwaysMultipartFormData = true;
     request.AddFile("file", file, "FileName.png", "application/octet-stream");
     request.AddParameter("options", "$fileOptions");
     request.AddParameter("folderPath", "/myfolder");
     RestResponse response = await client.ExecuteAsync(request);
     Console.WriteLine(response.Content);

 }&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 12 Jan 2024 16:33:49 GMT</pubDate>
    <dc:creator>naixs</dc:creator>
    <dc:date>2024-01-12T16:33:49Z</dc:date>
    <item>
      <title>Hhow upload a file using c# and a file stream?</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Hhow-upload-a-file-using-c-and-a-file-stream/m-p/904795#M70289</link>
      <description>&lt;P&gt;Hello everyone, I am trying to send pdf files to hubspot but the new api asks for a url as a parameter and I do not want to save the file in my application but save it directly in hubspot. The old version of the api does allow you to do this but it asks me to enable a scope ("file-manager-access") that seems to no longer be present with the new authentication. How can I send my files using bytes instead of a URL?&lt;BR /&gt;&lt;BR /&gt;reference urls:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://legacydocs.hubspot.com/docs/methods/files/v3/upload_new_file" target="_blank"&gt;https://legacydocs.hubspot.com/docs/methods/files/v3/upload_new_file&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://developers.hubspot.com/docs/api/files/files" target="_blank"&gt;https://developers.hubspot.com/docs/api/files/files&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;my code:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt; public async Task UploadFile2(string id, Stream stream) {

     static byte[] ConvertStreamToBytes(Stream streamData)
     {
         using (MemoryStream memoryStream = new MemoryStream())
         {
             streamData.CopyTo(memoryStream);
             return memoryStream.ToArray();
         }
     }

     byte[] file = ConvertStreamToBytes(stream);

     var options = new RestClientOptions("https://api.hubapi.com")
     {
         MaxTimeout = -1,
     };
     var client = new RestClient(options);
     var request = new RestRequest("/filemanager/api/v3/files/upload", Method.Post);
     request.AddHeader("Authorization", "Bearer my-bearer-token");
     request.AlwaysMultipartFormData = true;
     request.AddFile("file", file, "FileName.png", "application/octet-stream");
     request.AddParameter("options", "$fileOptions");
     request.AddParameter("folderPath", "/myfolder");
     RestResponse response = await client.ExecuteAsync(request);
     Console.WriteLine(response.Content);

 }&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 12 Jan 2024 16:33:49 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Hhow-upload-a-file-using-c-and-a-file-stream/m-p/904795#M70289</guid>
      <dc:creator>naixs</dc:creator>
      <dc:date>2024-01-12T16:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: Hhow upload a file using c# and a file stream?</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Hhow-upload-a-file-using-c-and-a-file-stream/m-p/905815#M70332</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/141810"&gt;@naixs&lt;/a&gt;&amp;nbsp;- note that uploading a file to HubSpot (using the files tool for example) does provide you with a signed URL you can use to read the data into working array for your code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Steve&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2024 19:57:06 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Hhow-upload-a-file-using-c-and-a-file-stream/m-p/905815#M70332</guid>
      <dc:creator>SteveHTM</dc:creator>
      <dc:date>2024-01-15T19:57:06Z</dc:date>
    </item>
  </channel>
</rss>

