Android Multipart HTTP Post не отправляет MIME-тип файла

Пытаюсь понять, что не так с моими кодировками. Я следил за публикацией в блоге от здесь .

Мне удалось получить коды для фактической загрузки файла в веб-сервис PHP. Однако по какой-то причине, хотя я явно установил тип MIME для файла, PHP показывает, что MIME - это просто пустая строка и поэтому отклонен.

Вот мои кодировки:

public String SendPost(String fn, String bid, String caption, String uid, String APIKey, String postHash) 
        throws ParseException, ClientProtocolException, IOException {
    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

    HttpPost httppost = new HttpPost(UrbURL);

    Log.i("POSTFN", fn);
    Log.i("POSTFN", bid);
    Log.i("POSTFN", caption);
    Log.i("POSTFN", uid);
    Log.i("POSTFN", APIKey);
    Log.i("POSTFN", postHash);

    String postAuth = uid + postHash;
    postAuth = md5(postAuth);
    postAuth = postAuth.substring(0, 16);
    //Log.i("POSTAUTH", postAuth);

    MultipartEntity mp = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

    /*File tempImg = new File(fn);
    FileBody bin = new FileBody(tempImg, "image/jpg");*/
    mp.addPart("business_photo", new FileBody(new File(fn), "image/jpg"));

    //StringBody s = new StringBody(bid, "text/plain", Charset.forName( "UTF-8" ));
    mp.addPart("business_id", new StringBody(bid, "text/plain", Charset.forName( "UTF-8" )));

    //s = new StringBody(caption, "text/plain", Charset.forName( "UTF-8" ));
    mp.addPart("photo_caption", new StringBody(caption, "text/plain", Charset.forName( "UTF-8" )));

    //s = new StringBody(uid, "text/plain", Charset.forName( "UTF-8" ));
    mp.addPart("user_id", new StringBody(uid, "text/plain", Charset.forName( "UTF-8" )));

    //s = new StringBody(APIKey, "text/plain", Charset.forName( "UTF-8" ));
    mp.addPart("apikey", new StringBody(APIKey, "text/plain", Charset.forName( "UTF-8" )));

    //s = new StringBody(postAuth, "text/plain", Charset.forName( "UTF-8" ));
    mp.addPart("auth", new StringBody(postAuth, "text/plain", Charset.forName( "UTF-8" )));

    httppost.setEntity(mp);

    String response = EntityUtils.toString( httpclient.execute( httppost ).getEntity(), "UTF-8" );

    httpclient.getConnectionManager().shutdown();

    return response;
}

Большое спасибо раньше:)

10
задан Jonas 31 August 2011 в 14:03
поделиться