Rest api example for file upload

I’m trying to upload a file with REST Api. List file functions well but with Uplaad I get a Bad Request error. Here is the Code C# with which I tried to upload the file

using (var httpClient = new HttpClient())
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(“Bearer”, apikey);
using (var request = new HttpRequestMessage(new HttpMethod(“POST”), “”))
var multipartContent = new MultipartFormDataContent();
var data = File.ReadAllText(filePath);
multipartContent.Add(new StringContent(fileType), “purpose”); // answers
multipartContent.Add(new StringContent(data, Encoding.UTF8, “application/json”), “file”);
request.Content = multipartContent;
var response = httpClient.SendAsync(request).Result;
var status = response.StatusCode;

Thank you

1 Like

I’m getting the same error with DALL-E’s Edit Image API in Swift. Any luck here?