从库中选择图像,我可以上传流,但得到错误"参数无效".在尝试转换为WCF中的图像时.
Android代码创建与REST服务的连接,并将图像上传为Byte []:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK){
Uri targetUri = data.getData();
Bitmap bitmap;
try {
bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(targetUri));
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 6, out);
DefaultHttpClient httpClient = new DefaultHttpClient();
byte[] sendData = out.toByteArray();
HttpPost postRequest = new HttpPost("http://www.thehost.dk/MobileService/Service.svc/uploadpicture/");
ByteArrayBody bab = new ByteArrayBody(sendData, "picture.jpg");
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("image", bab);
postRequest.setEntity(reqEntity);
httpClient.execute(postRequest);
Run Code Online (Sandbox Code Playgroud)
WCF C#代码接收流并尝试转换为图像,但收到错误:
public void UploadPicture(Stream imageData)
{
try
{
byte[] image = StreamToBytes(imageData); …Run Code Online (Sandbox Code Playgroud)