当上传间歇性SSL错误使用Facebook的Andr​​oid的SDK 3.0张照片 [英] Intermittent SSL error when uploading photos using Facebook Android SDK 3.0

查看:381
本文介绍了当上传间歇性SSL错误使用Facebook的Andr​​oid的SDK 3.0张照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的Facebook的Andr​​oid SDK 3.0照片上传到我的专辑。一切正常,但有时第一次上传失败,一个有些出人意料的SSL错误。

I'm using Facebook Android SDK 3.0 to upload a photo to my album. Everything works, but sometimes the first upload fails with a somewhat unexpected SSL error.

请参阅功能 toHttpConnection 的<一个href="https://github.com/facebook/facebook-android-sdk/blob/master/facebook/src/com/facebook/Request.java"相对=nofollow> Request.java 。

try {
        connection = createConnection(url);

        serializeToUrlConnection(requests, connection);
    } catch (IOException e) {
        // THIS IS WHERE THE ERROR ORIGINATES FROM!
        throw new FacebookException("could not construct request body", e);
    } catch (JSONException e) {
        throw new FacebookException("could not construct request body", e);
    }

悬停电子在Eclipse中显示以下信息:

Hovering e in Eclipse shows this information:

javax.net.ssl​​.SSLException:写入错误:SSL = 0x4f033008:系统调用过程中的I / O错误,管道中断 javax.net.ssl​​.SSLException:写入错误:SSL = 0x4f033008:I / O错误系统调用过程中,管道中断 写入错误:SSL = 0x4f033008:I /系统调用过程中O错误,管道中断 [1277468208,0,1279934152,48 1280860304,26 1280860480,58 1280859576,11 1280859696,4,1277492792,1,1280859640,7,1280233152,169,1280233264,36 1280230744,6,1280236632,0,1280236576 ,0,1280238568,6,1280238512,2,1278731744,21 1279835640,23 1278097880,2,1279841920,28 1279843376,2,1277300032,6] 空

javax.net.ssl.SSLException: Write error: ssl=0x4f033008: I/O error during system call, Broken pipe javax.net.ssl.SSLException: Write error: ssl=0x4f033008: I/O error during system call, Broken pipe Write error: ssl=0x4f033008: I/O error during system call, Broken pipe [1277468208, 0, 1279934152, 48, 1280860304, 26, 1280860480, 58, 1280859576, 11, 1280859696, 4, 1277492792, 1, 1280859640, 7, 1280233152, 169, 1280233264, 36, 1280230744, 6, 1280236632, 0, 1280236576, 0, 1280238568, 6, 1280238512, 2, 1278731744, 21, 1279835640, 23, 1278097880, 2, 1279841920, 28, 1279843376, 2, 1277300032, 6] null

这是在SDK中的错误?别的任何人遇到这样?而更重要的是,如何解决呢?

Is this a bug in the SDK? Did anybody else encounter this? And more importantly, how do I fix it?

推荐答案

我的几乎的准备解决我的previous(删除)的答案,直到我遇到了这篇文章:<一个href="http://vikaskanani.word$p$pss.com/2011/01/11/android-upload-image-or-file-using-http-post-multi-part/" rel="nofollow">http://vikaskanani.word$p$pss.com/2011/01/11/android-upload-image-or-file-using-http-post-multi-part/

I was almost ready to settle for my previous (removed) answer, until I came across this article: http://vikaskanani.wordpress.com/2011/01/11/android-upload-image-or-file-using-http-post-multi-part/

我决定给它一个镜头,它似乎工作!这是我的code:

I decided to give it a shot, and it seems to work! Here's my code:

for (Bitmap b : bitmaps) {
    // id is just a string
    String response = executeUpload(b, id);

    // do something with the response
}

private String executeUpload(Bitmap b, String id) throws MalformedURLException, IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    b.compress(CompressFormat.PNG, 100, baos);
    byte[] data = baos.toByteArray();

    HttpPost postRequest = new HttpPost("https://graph.facebook.com/me/photos");
    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, 3000);
    HttpClient httpClient = new DefaultHttpClient();
    httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(2, true));

    ByteArrayBody bab = new ByteArrayBody(data, id + ".png");
    MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    reqEntity.addPart("access_token", new StringBody(activeFacebookAccessToken));
    reqEntity.addPart("message", new StringBody(""));
    reqEntity.addPart("picture", bab);
    postRequest.setEntity(reqEntity);
    HttpResponse response = httpClient.execute(postRequest);
    BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
    String s;
    StringBuilder builder = new StringBuilder();
    while ((s = reader.readLine()) != null) {
        builder = builder.append(s);
    }

    return builder.toString();
}

正如上面的链接讨论,您必须安装最新的的HttpClient (在的 http://hc.apache.org/downloads.cgi )。

要注意的另一个重要的事情是,Facebook的支持720像素的两种维度的最大图像尺寸。在我的code,我缩放位图是在该尺寸的限制做的上传极大地提高性能了。

Another important thing to note is that Facebook supports a maximum image size of 720 px in either dimension. In my code I'm scaling the bitmap to be within that size limit before doing the upload which greatly improves performance.

这篇关于当上传间歇性SSL错误使用Facebook的Andr​​oid的SDK 3.0张照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆