简体   繁体   中英

Artifactory REST Deploy screwing up upload

I am trying to deploy artifacts to artifactory using their REST API, however all my files end up having

-------------------------------28947758029299 Content-Disposition: form-data; name="test.txt"; filename="new2.txt" Content-Type: application/octet-stream

appended to the file. Here is my code (keep in mind this is only me testing the concept...the code will be cleaned after I get a success)

  var uriString = "artifactoryuri";
  var uri = new Uri(uriString);
  var credentialCache = new CredentialCache{{uri, "Basic",new NetworkCredential("UN", "PW")}};
  var restClient = new RestClient(uriString);
  var restRequest = new RestRequest(Method.PUT){Credentials = credentialCache};
  restRequest.AddFile("test.txt", @"pathto\new2.txt");
  var restResponse = restClient.Execute(restRequest);

How can I fix this? Is it because it is a text file and artifactory tends to store executables and such? If so, I can live with that. This will be used to upload chm files currently.

This is caused by the AddFile method - RestSharp will create a multipart/form request by default. I could not find a good solution for preventing this behavior, although many people ask about it. You can take a look at Can RestSharp send binary data without using a multipart content type? and PUT method and send raw bytes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM