我想将目录文件上传到推荐 api(使用 ruby 语言的 Azure 认知服务。
使用 C#,我将获得下一个代码(摘自https://github.com/Microsoft/Cognitive-Recommendations-Windows/blob/master/Sample/RecommendationsApiWrapper.cs):
public CatalogImportStats UploadCatalog(string modelId, string catalogFilePath, string catalogDisplayName)
{
Console.WriteLine("Uploading " + catalogDisplayName + " ...");
string uri = BaseUri + "/models/" + modelId + "/catalog?catalogDisplayName=" + catalogDisplayName;
using (var filestream = new FileStream(catalogFilePath, FileMode.Open, FileAccess.Read))
{
var response = _httpClient.PostAsync(uri, new StreamContent(filestream)).Result;
if (!response.IsSuccessStatusCode)
{
throw new Exception(
String.Format("Error {0}: Failed to import catalog items {1}, for model {2} \n reason {3}",
response.StatusCode, catalogFilePath, modelId, ExtractErrorInfo(response)));
}
var jsonString = ExtractReponse(response);
var catalogImportStats = JsonConvert.DeserializeObject<CatalogImportStats>(jsonString);
return catalogImportStats;
}
如何使用 ruby 和 http 客户端将目录文件上传到认知服务?我需要一个基本的示例代码。
谢谢