在 Android 的不倒翁上从 sd 卡上传图像 [英] Upload image from sd-card on tumbler in Android

查看:21
本文介绍了在 Android 的不倒翁上从 sd 卡上传图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用 http://... URL 上传图片.但我不想使用 URL.我想从手机的本地 SD 卡上传图像到不倒翁.我尝试了所有这些解决方案 从 Android 上传图像到 tumblr API 但什么也没有为我工作.

I have uploaded image using a http://... URL. but i dont want to use URL .I want to upload image on tumbler from local sdcard of mobile. I tried all these solutions Uploading Images to tumblr API from Android but nothing worked for me.

我通过这样的 URL 发布图片:-

i posted image by URL like this :-

File fil = savebitmap(pattern_a);
        HttpPost hpost = new HttpPost("http://api.tumblr.com/v2/blog/"
                + strBlogName.replace(" ", "%20") + ".tumblr.com/post");
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);

nameValuePairs.add(new BasicNameValuePair("type", "photo"));
            nameValuePairs.add(new BasicNameValuePair("caption", "hello"));
            nameValuePairs.add(new BasicNameValuePair("source","http://pchtanks.com/wp-content/uploads/2013/10/tropical-fish11.jpg"));

更新

我正在使用此代码

     nameValuePairs.add(new BasicNameValuePair("type", "photos"));
     nameValuePairs.add(new BasicNameValuePair("set_total", "1"));
             nameValuePairs.add(new BasicNameValuePair("name", "Akanksha"));
             nameValuePairs.add(new BasicNameValuePair("caption", "Hello yar"));

             nameValuePairs.add(new BasicNameValuePair("original","0"));
             nameValuePairs.add(new BasicNameValuePair("data", fil.getAbsolutePath().toString()));
             nameValuePairs.add(new BasicNameValuePair("source", encodedImage));
//              localContentValues2.put("tumblr_post_id", Long.valueOf(paramLong));
             nameValuePairs.add(new BasicNameValuePair("width", String.valueOf(pattern_a.getWidth())));
             nameValuePairs.add(new BasicNameValuePair("height", String.valueOf(pattern_a.getHeight())));
                localArrayList.add(nameValuePairs);

hpost.setEntity(new UrlEncodedFormEntity(nameValuePairs));



    consumerconsumer.sign(hpost);

    DefaultHttpClient client = new DefaultHttpClient();
    org.apache.http.HttpResponse resp = null;
    resp = client.execute(hpost);

    result = EntityUtils.toString(resp.getEntity());
    PrintLog.LOGV("Result : " + result);

我得到了这样的编码图像:-

I got the encodedImage like this :-

ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
    pattern_a.compress(Bitmap.CompressFormat.JPEG, 100, stream); 
    byte[] byteArray = stream.toByteArray(); 
    String encodedImage = Base64.encodeToString(byteArray, Base64.DEFAULT);

我收到错误:- 床位请求,帖子不能为空.

我想我在参数中遗漏了一些东西,或者我发送了任何错误的标签.

I think i am missing something in parameter or i am sending any wrong tag.

有没有机构有解决办法.
我已经下载了 jumblr jar 文件.但我不知道如何使用它.我的工作是否可以没有 jumbler.请回复.

Do any body have any solution.
I have downloaded jumblr jar file. but i don't know how to use it. Is my work is possible without jumbler. Please reply.

推荐答案

源不需要 URL.它需要 URI.您是否尝试过 :nameValuePairs.add(new BasicNameValuePair("source","file:///sdcard/img.png")); ?

The source does not expect URL. It expects URI. Did you try :nameValuePairs.add(new BasicNameValuePair("source","file:///sdcard/img.png")); ?

此外,您可以指定 data 并使用字节缓冲区提供图像的实际字节数,而不是源代码

Moreover, instead of source, you can specify data and supply the actual bytes of the image using a bytebuffer

这篇关于在 Android 的不倒翁上从 sd 卡上传图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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