我需要发布的网址 :: http://54.218.73.244:7002/Details/
我尝试了什么::
key
drawable中有image.jpg
activity_main.xml中
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="135dp"
android:layout_height="181dp"
android:layout_alignParentTop="true"
android:layout_marginTop="32dp"
android:clickable="false"
android:src="@drawable/image" />
<Button
android:id="@+id/SUBMIT_BUTTON_ID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="47dp"
android:text="SUBMIT" />
</LinearLayout>
我需要的是什么::
我是android和amp;的新手图片上传,请轻松回答
答案 0 :(得分:0)
答案 1 :(得分:0)
我使用Http multipart执行图像和视频上传。遗憾的是,这些不是android sdk的一部分,因此我们必须将多部分lib作为项目的一部分导入。
Here is an awesome answer that helped me.
不要忘记交叉检查您添加为multipart的键值对正是服务器所期望的。
答案 2 :(得分:0)
试试这段代码..
private void uploadPhoto(Bitmap photo)
{
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
try
{
ContentBody contentPart = null;
if(photo != null)
{
String filename="temp.jpg";
ByteArrayOutputStream bos = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.JPEG, 100, bos);
contentPart = new ByteArrayBody(bos.toByteArray(), filename);
String root = "sdcard path";
File myDir = new File(root );
myDir.mkdirs();
String fname = filename;
File file = new File (myDir, fname);
if (file.exists ()) file.delete ();
try {
FileOutputStream out = new FileOutputStream(file);
photo.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
reqEntity.addPart("image", contentPart);
}
String url = "your url";
String response = multipost(url, reqEntity);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
这里是multipost的代码
public String multipost(String urlString, MultipartEntity reqEntity) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(urlString);
//
try {
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
InputStream is = response.getEntity().getContent();
}
catch(Exception e)
{
Log.e("tag", "Error: "+e.toString());
}
return null;
}
然后调用uploadphoto方法...当你想要.... 希望这会对你有所帮助...... :)
答案 3 :(得分:0)
尝试这个,它对我来说很好