I am new to Nexus and I am trying to upload a file to a Nexus Repo. I have pulled the swagger endpoint and looked through the help documentation and everything seems to be correct, in fact it worked once prior to just stopping. I am using the following C# code to post my request to our local Nexus API instance and receiving the following error message in the response:
Status Code: BadRequest (400)
[
{
"id": "*",
"message": "No assets found in upload"
},
{
"id": "asset1",
"message": "Unknown component field 'asset1'"
},
{
"id": "asset1.filename",
"message": "Unknown component field 'asset1.filename'"
}
]
Here is my C# Code:
private bool InsertComponent()
{
//Local Variable Declaration
var returnValue = false;
var form = default(System.Net.Http.MultipartFormDataContent);
var response = default(System.Net.Http.HttpResponseMessage);
var responseStr = string.Empty;
var responseObj = default(Newtonsoft.Json.Linq.JObject);
try
{
using (var Client = new System.Net.Http.HttpClient())
{
//Add the authorization token to the request header
Client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", "<Base64Creds>");
//Build Form Object
form = new System.Net.Http.MultipartFormDataContent();
form.Add(new System.Net.Http.StringContent("/Website/Supplier/JoshTest"), "raw.directory");
form.Add(new System.Net.Http.StringContent("Josh.txt"), "raw.asset1.filename");
//Add the image to form
var Image = System.IO.File.ReadAllBytes(@"J:\Projects\Nexus Research\Josh.txt");
form.Add(new System.Net.Http.ByteArrayContent(Image, 0, Image.Length), "raw.asset1");
//Post to the API
response = Client.PostAsync(this.NexusUrlBase + "/service/rest/v1/components?repository=repo-release-packages", form).Result;
if (response.StatusCode == System.Net.HttpStatusCode.NoContent)
{
//Get Server Response
responseStr = response.Content.ReadAsStringAsync().Result;
if (!string.IsNullOrEmpty(responseStr))
{
//Convert from raw json string into a JSON Object
responseObj = Newtonsoft.Json.Linq.JObject.Parse(responseStr);
if (responseObj != null)
{
}
}
else
{
throw new Exception("Failed to insert image into digital media storage bucket. Empty Response Returned");
}
}
else
{
//Get Server Response
responseStr = response.Content.ReadAsStringAsync().Result;
if (!string.IsNullOrEmpty(responseStr))
{
System.IO.File.WriteAllText(@"J:\Projects\Nexus Research\error.json", Newtonsoft.Json.Linq.JArray.Parse(responseStr).ToString(Newtonsoft.Json.Formatting.Indented));
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return returnValue;
}
It did work once the other day and uploaded the text file without issue but then suddenly a few days later I started receiving the ba request error.
I have looked at the following documentation and everything appears to be correct, please help"