Hey,
ich habe den Code hier:
PHP Code:
import java.io.File;
import java.nio.charset.Charset;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.util.EntityUtils;
public class UploadTest {
public static void main(String[] args) throws Exception {
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost httppost = new HttpPost("http://uploads.im/api?upload=");
File file = new File("E:/d.jpg");
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(file);
mpEntity.addPart("file", cbFile);
// mpEntity.addPart( "parameter", new StringBody("format=txt"));
httppost.setEntity(mpEntity);
System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
System.out.println(response.getStatusLine());
if (resEntity != null) {
System.out.println(EntityUtils.toString(resEntity));
}
if (resEntity != null) {
resEntity.consumeContent();
}
httpclient.getConnectionManager().shutdown();
}
}
und der Upload funktioniert auch und ich komme alles zurück wie hier beschrieben

.
(Also
PHP Code:
({"status_code":200,"status_txt":"OK","data":{"img_name":"abcde.png","img_url":"http:\/\/s1.uploads.im\/abcde.png","img_view":"http:\/\/uploads.im\/abcde.png","img_width":167,"img_height":288,"img_attr":"width=\"167\" height=\"288\"","img_size":"36.1 KB","img_bytes":37002,"thumb_url":"http:\/\/s1.uploads.im\/t\/abcde.png","thumb_width":100,"thumb_height":90,"source":"http:\/\/www.google.com\/images\/srpr\/nav_logo66.png","resized":"0"}});
)
Jetzt will ich aber bloß die ImageUrl und dafür soll ich dem den Parameter "format=txt" (
RAW TEXT
format=txt will output just the image URL.
) mitgeben.
Da ist mir bloß nicht so ganz klar wie ich das machen muss, der HttpPost wird ja aus meinem MultipartEntity gemacht und eigentlich müsste ich da ja mit dem .addPart einfach noch den Parameter hinzufügen oder?
Habe schon Sachen probiert wie
PHP Code:
mpEntity.addPart( "parameter", new StringBody("format=txt"));
Aber will nicht so wirklich klappen, obwohl das ja genau so ist wie drüber bei dem addPart von der Datei

Fehler kommt keiner aber ich bekomme halt trotzdem immer das komplette zurück