Android图片上传到upload.im API

时间:2015-02-09 08:36:26

标签: php android http http-post

我需要将图像从本地目录上传到API。

private void uploadIm() {
		MultipartEntity multipartEntity = new MultipartEntity();
		File image1 = new File(getFilesDir().getAbsolutePath()+"/finalImage.jpg");
		multipartEntity.addPart("upload", new FileBody(image1));
		HttpClient client = new DefaultHttpClient();
		HttpPost post = new HttpPost("http://uploads.im/api");
		post.setEntity(multipartEntity);
		HttpResponse response;
		try {
			response = client.execute(post);
			HttpEntity resEntity = response.getEntity();
			String response_str = EntityUtils.toString(resEntity);
			Log.e("response", response_str);
			Toast.makeText(getApplicationContext(), "done", Toast.LENGTH_LONG).show();
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

这一直让我“通过远程服务器重置连接”警告并关闭。我使用的API是uploads.im,这里是Uploads.im。我不明白我在这里做错了什么。请帮忙或建议替代方案。谢谢!

0 个答案:

没有答案