Upload image from sd-card on tumbler in Android

强颜欢笑 提交于 2019-12-02 08:09:09

问题


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.

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"));

UPDATE

I am using this code

     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 am getting Error : - Bed request, Post can not be empty.

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

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.


回答1:


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

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



来源:https://stackoverflow.com/questions/21739014/upload-image-from-sd-card-on-tumbler-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!