title: "Converted/Optimized" C# Code - HTTP Client Response Code 404 Error
body: <p>I'm trying after &quot;converted/optimized&quot; a C# Unity Project to my Visual Studio in C# to work for me (the code)...</p>
  <p>i used this github lib for nft.storage
  <a href="https://github.com/filipepolizel/unity-nft-storage/blob/main/NFTStorageClient.cs" rel="nofollow noreferrer">https://github.com/filipepolizel/unity-nft-storage/blob/main/NFTStorageClient.cs</a></p>
  <p>If i call then with:</p>
  <p><code>string pathtofile = @&quot;&quot; + AppDomain.CurrentDomain.BaseDirectory + &quot;testfile.txt&quot;;</code></p>
  <p><code>await NFTStorageTest.Upload(NFTStorageTest.nftStorageApiUrl, pathtofile);</code></p>
  <p>i get this error:</p>
  <p><code>System.Net.Http.HttpRequestException: Response status code does not indicate success: 404 (Not Found).    at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()    at Main.net.NFTStorageTest.Upload(String uri, String pathFile) in C:\...\NFTStorageTest.cs:line 173 </code></p>
  <p>Here is my Code:</p>
  <pre><code>    // nft.storage API endpoint 
      internal static readonly string nftStorageApiUrl = &quot;https://api.nft.storage/&quot;;
  
      // HTTP client to communicate with nft.storage
      internal static readonly HttpClient nftClient = new HttpClient();
  
      // http client to communicate with IPFS API
      internal static readonly HttpClient ipfsClient = new HttpClient();
  
      // nft.storage API key
      public string apiToken = &quot;XXX&quot;;
  
      public void Start()
      {
          nftClient.DefaultRequestHeaders.Add(&quot;Accept&quot;, &quot;application/json&quot;);
          if (apiToken != null)
          {
              nftClient.DefaultRequestHeaders.Add(&quot;Authorization&quot;, &quot;Bearer &quot; + apiToken);
          }
          else
          {
              // log in console in case no API key is found during initialization
              Console.WriteLine(&quot;Starting NFT Storage Client without API key, please call 'SetApiToken' method before using class methods.&quot;);
          }
      }
  
      public async Task&lt;NFTStorageUploadResponse&gt; UploadDataFromFile(string path)
      {
          StreamReader reader = new StreamReader(path);
          string data = reader.ReadToEnd();
          reader.Close();
          Console.WriteLine(&quot;Uploading...&quot;);
          return await UploadDataFromString(data);
      }
  
  
      public async Task&lt;NFTStorageUploadResponse&gt; UploadDataFromString(string data)
      {
          string requestUri = nftStorageApiUrl + &quot;/upload&quot;;
          string rawResponse = await Upload(requestUri, data);
          string jsonString = JsonConvert.SerializeObject(rawResponse);
  
          NFTStorageUploadResponse parsedResponse = JsonConvert.DeserializeObject&lt;NFTStorageUploadResponse&gt;(jsonString);
          return parsedResponse;
      }
  
      public static async Task&lt;string&gt; Upload(string uri, string pathFile)
      {
  
          byte[] bytes = File.ReadAllBytes(pathFile);
  
          using (var content = new ByteArrayContent(bytes))
          {
              content.Headers.ContentType = new MediaTypeHeaderValue(&quot;*/*&quot;);
  
              //Send it
              var response = await nftClient.PostAsync(uri, content);
              response.EnsureSuccessStatusCode();
              Stream responseStream = await response.Content.ReadAsStreamAsync();
              StreamReader reader = new StreamReader(responseStream);
              return reader.ReadToEnd();
          }
      }`
  </code></pre>
  <p>whats my mistake and how can i fix it?</p>