[FACE API]错误“InvalidImageSize:图片大小太小或太大”对于每个请求 [英] [FACE API] error "InvalidImageSize: image size is too small or too big" for each request
问题描述
我正在使用cpprestsdk与FACE API进行通信。每次我尝试将图像作为流加载时(请参阅下面的代码)我收到错误:"图片大小太小或太大big"。$
通过URL加载相同的图像正常工作,并以JSON格式返回正确的结果。
I am using cpprestsdk in order to communicate with FACE API. Each time I try to load an image as a stream (see code below) I get an error: "image size is too small or too big".
Loading the same image via URL works correctly and proper result is returned in JSON.
有没有解决方法?
return file_stream<unsigned char>::open_istream(filename, std::ios_base::in | std::ios_base::binary)
.then([=](pplx::task<basic_istream<unsigned char>> previousTask)
{
auto fileStream = previousTask.get();
auto client = http_client{ U("https://api.projectoxford.ai/face/v1.0/detect") };
auto query = uri_builder()
.append_query(U("subscription-key"), subscriptionKey)
.to_string();
return client
.request(methods::POST, query, concurrency::streams::istream(fileStream), U("application/octet-stream"))
.then([fileStream](pplx::task<http_response> previousTask)
{
fileStream.close();
return previousTask.get().extract_json();
});
return pplx::task_from_result(web::json::value());
});
推荐答案
嗨rolobambolo,
Hi rolobambolo,
感谢报道。目前,我们的服务并不完全支持分块传输编码请求。根据您的情况,我们建议您在请求函数中添加'content_length'参数,即
Thanks for reporting. Currently, our service doesn't totally support chunked transfer encoding request. As work around in your case, we suggest to add 'content_length' parameter in you request function, i.e.,
return 客户端
。 请求 ( 方法 :: POST , 查询 , 并发 :: 流 :: istream ( fileStream ),
fileStream.streambuf()。size(), U ( " application / octet-stream" ))
。 然后 ([ fileStream ]( pplx :: 任务 < http_response> previousTask )
{
fileStream 。 关闭 ();
<跨度>返回 previousTask 。 获取 ()。 extract_json ();
});
return client
.request(methods::POST, query, concurrency::streams::istream(fileStream),
fileStream.streambuf().size(), U("application/octet-stream"))
.then([fileStream](pplx::task<http_response> previousTask)
{
fileStream.close();
return previousTask.get().extract_json();
});
希望这可以帮到你。
谢谢
这篇关于[FACE API]错误“InvalidImageSize:图片大小太小或太大”对于每个请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!