本文介绍了使用POST,PHP和Android上传图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想上传的Android使用MultipartEntity图像后得到以下错误信息:
I am getting the following error message after trying to upload an image using a MultipartEntity in android:
Error: Problem with [picture] (File upload error 4)
我用下面的code上传图片:
I am using the following code to upload the image:
String url = "http://www.uploadurl.com/api/files.php";
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(url);
MultipartEntity multiEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Temp/" + IMAGE_FILENAME);
ContentBody cBody = new FileBody(file);
StringBody sb1 = new StringBody(getNameFormatted());
StringBody sb2 = new StringBody(getDeviceID());
MultipartEntity multipartContent = new MultipartEntity();
multipartContent.addPart("name", sb1);
multipartContent.addPart("uuid", sb2);
multipartContent.addPart("picture", cBody);
httpPost.setEntity(multipartContent);
HttpResponse response = httpClient.execute(httpPost, localContext);
我不知道我在做什么用code非常相似,这只是使用JSON数组作为实体的一部分,而不是逐个添加所有的过去错了,我已经上传的图片。我认为它得到的东西做的图像设置到其ContentBody可能的方式吗?我真的不知道。
I'm not sure what i'm doing wrong, I have uploaded images using code very similar to this in the past only using a JSON array as a part of the entity rather than adding all of them individually. I think it's got something to do with the way the image is set into its ContentBody maybe? I'm really not sure.
推荐答案
请参阅:的
这篇关于使用POST,PHP和Android上传图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!