私は普及したサービスであるDailyboothに、新しいAPIを使ってdocumented hereの方法で写真をアップロードしようとしています。無効なContent-Lengthがサーバーに送信されますか?
問題はサーバーの応答していることである。
<html><head><title>411 Length Required</title>...
私はこのデータを送信するために使用しているコードはここにある:
// 2: Build request
HttpClient httpclient = new DefaultHttpClient();
SharedPreferences settings = DailyboothShared.getPrefs(DailyboothTakePhoto.this);
String oauth_token = settings.getString("oauth_token", "");
HttpPost httppost = new HttpPost(
"https://api.dailybooth.com/v1/pictures.json?oauth_token=" + oauth_token);
Log.d("upload", "Facebook: " + facebook);
Log.d("upload", "Twitter: " + twitter);
try {
InputStream f = getContentResolver().openInputStream(snap_url);
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
entity.addPart("picture", new InputStreamBody(f, snap_url.getLastPathSegment()));
entity.addPart("blurb", new StringBody(blurb));
entity.addPart("publish_to[facebook]", new StringBody(facebook));
entity.addPart("publish_to[twiter]", new StringBody(twitter));
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost);
Log.d("upload", response.toString());
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == 200) {
// do something?
} else {
Log.d("upload", "Something went wrong :/");
}
Log.d("upload", EntityUtils.toString(response.getEntity()));
} catch (Exception ex) {
ex.printStackTrace();
}
私は「何何のアイデアを得ませんしました私は間違っている。
ありがとう、私はこれらの提案を試みます。残念ながら、私は簡単に "ファイル"オブジェクトを取得しようとしましたが、Androidシステムは私にこれを可能にしたくありません。 –
どのようにファイルを読むことができませんか? java.io.FileはSDKの一部であるため、アンドロイドでこれを行うことができます。多分許可の問題かもしれません。 – CodegistCRest
私はカメラと他のアプリケーションからファイルを取得しようとしていますが、何らかの理由でファイルが開かない "content:// blah/blah/blah"というURLを返しました。しかし、私はファイル記述子を使用するように変更しました。これにより、長さを「統計」することができ、それが機能しました。ありがとう:D –