2011-10-03 9 views
8

संभव डुप्लिकेट:
Send post data in androidएंड्रॉयड एक छवि भेज और यूआरएल को बचाने

प्रपत्र डेटा के साथ http पोस्ट के माध्यम से एक छवि भेज कैसे यानी छवि नाम आदि

को एक निर्दिष्ट यूआरएल .. जो एएसपीएक्स का यूआरएल है।

+0

और आपको ऐसा क्यों लगता है कि वे अलग होना चाहिए? – Reno

उत्तर

19

चेक शीर्षक, कैप्शन, नाम आदि के साथ छवि भेजा जा रहा है के लिए इस कोड को,

HttpClient httpClient = new DefaultHttpClient(); 
    HttpPost postRequest = new HttpPost("You Link"); 
    MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); 
    reqEntity.addPart("name", new StringBody("Name")); 
    reqEntity.addPart("Id", new StringBody("ID")); 
    reqEntity.addPart("title",new StringBody("TITLE")); 
    reqEntity.addPart("caption", new StringBody("Caption")); 
    try{ 
     ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
     bitmap.compress(CompressFormat.JPEG, 75, bos); 
     byte[] data = bos.toByteArray(); 
     ByteArrayBody bab = new ByteArrayBody(data, "forest.jpg"); 
     reqEntity.addPart("picture", bab); 
    } 
    catch(Exception e){ 
     //Log.v("Exception in Image", ""+e); 
     reqEntity.addPart("picture", new StringBody("")); 
    } 
    postRequest.setEntity(reqEntity);  
    HttpResponse response = httpClient.execute(postRequest); 
    BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8")); 
    String sResponse; 
    StringBuilder s = new StringBuilder(); 
    while ((sResponse = reader.readLine()) != null) { 
     s = s.append(sResponse); 
    } 

कहाँ बिटमैप छवि बिटमैप है।

यदि आपको कोई कठिनाई मिलती है तो मुझे बताएं।

धन्यवाद वेंकी।

+0

ग्रेट वन। वीडियो अपलोड करने के बारे में क्या? –

+0

+1 धन्यवाद आदमी। आपने मेरा दिन बचाया एक बार फिर धन्यवाद। – Sajmon

+0

लेकिन यह एंड्रॉइड स्टूडियो @ वेन्की –

संबंधित मुद्दे