如何在webservices中发送jpg图像 [英] how to send jpg image in webservices

查看:63
本文介绍了如何在webservices中发送jpg图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个POST网络服务,需要图像作为MIME类型规范的帖子正文。





我发送图片

http://media.stacksbowers.com/4130/3030/3030/3031/3232/35/A0000001225-uscoin-zoom-1.JPG





但回复显示



{error:{消息:不支持使用MIME / jpeg,image / png和image / gif以外的MIME类型发布图像,class:SIMPLE-ERROR,superclasses:[SIMPLE-CONDITION, ERROR]}}



这是我正在使用的代码。







  var  client33 =  new  RestClient(  https://uat2-server.auctionmobility.com/v1/auction-lot/1-TPRZ/图像的access_token = 1-1-87857099-8ec5-4c4a-836c-abf8cf1c6728\" )?; 
var request = new RestRequest(Method.POST);
request.AddHeader( content-type multipart / form-data);
request.AddParameter( multipart / form-data Content-Disposition:form-data; name = \image [] \; filename = \A0000098522-uscoin-thumb- 1-0.JPEG \Content-Type:image / jpeg,ParameterType.RequestBody);
request.AddParameter( image [],Convert.ToBase64String(imageBytes));
IRestResponse response33 = client33.Post(request);









imageBytes是图像的字节数组

解决方案

- 将图像作为字节数组,然后将其转换为base64字符串。

- 通过网络服务发送图像

-另一方面反过来获取图像数据。

- 然后你可以将图像保存到磁盘或分贝

Hi,
I have a POST web service that requires image as the post body with MIME type specification.


I am sending an image
http://media.stacksbowers.com/4130/3030/3030/3031/3232/35/A0000001225-uscoin-zoom-1.JPG


But the response shows

{"error":{"message":"Posting images with MIME types other than image/jpeg, image/png, and image/gif is not supported","class":"SIMPLE-ERROR","superclasses":["SIMPLE-CONDITION","ERROR"]}}

This is the code I am using.



var client33 = new RestClient("https://uat2-server.auctionmobility.com/v1/auction-lot/1-TPRZ/image?access_token=1-1-87857099-8ec5-4c4a-836c-abf8cf1c6728");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "multipart/form-data");
request.AddParameter("multipart/form-data", "Content-Disposition:                    form-data;name=\"image[]\"; filename=\"A0000098522-uscoin-thumb-1-0.JPEG\"Content-Type: image/jpeg", ParameterType.RequestBody);
request.AddParameter("image[]", Convert.ToBase64String(imageBytes));
IRestResponse response33 = client33.Post(request);





imageBytes is the byte array of image

解决方案

-Get the image as byte array and then convert it to base64 string.
-Send the image through the web service
-Do the opposite on the other side to get back the image data.
-Then you can save the image to disk or in db


这篇关于如何在webservices中发送jpg图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆