Having some trouble uploading photo

413 views
Skip to first unread message

Christopher Biscardi

unread,
Aug 19, 2011, 12:03:20 AM8/19/11
to Tumblr API Discussion
I'm trying to upload a photo post and I'm getting this error returned
from Tumblr:

{"meta":{"status":400,"msg":"Bad Request"},"response":{"errors":
["Error uploading photo."]}}

could this be because I'm uploading my file in the wrong format or
maybe a header issue?

any insight is much appreciated.

GG

unread,
Jul 19, 2012, 6:28:04 PM7/19/12
to tumbl...@googlegroups.com
Ever find a solution to this?  I have the same problem.

Devra Johnson

unread,
Jul 20, 2012, 12:35:20 AM7/20/12
to tumbl...@googlegroups.com
What language are you working in? 

GG

unread,
Jul 21, 2012, 4:13:50 PM7/21/12
to tumbl...@googlegroups.com
Javascript.  Using PhoneGap and jsOauth.  I think its because the image is base64 encoded. Unfortunately, thats my only option with phonegap.

Devra Johnson

unread,
Jul 21, 2012, 6:27:02 PM7/21/12
to tumbl...@googlegroups.com
Sorry, I’m working in C#.  (I’m also familiar with the PHP and Python examples.)  Have you read the thread on posting photo(s), https://groups.google.com/forum/?fromgroups#!topic/tumblr-api/IDI4QFNMAE4?
 
From: GG
Sent: Saturday, July 21, 2012 4:13 PM
Subject: Re: Having some trouble uploading photo
 

GG

unread,
Jul 21, 2012, 8:54:02 PM7/21/12
to tumbl...@googlegroups.com
Ya 100 times =(  Our problem is not related to auth, iIts related to image encoding.

Devra Johnson

unread,
Jul 21, 2012, 11:27:50 PM7/21/12
to tumbl...@googlegroups.com
I see.  The code I have for uploading a photo starts with the bytes for the image.  Can you decode the base64 encoded image and get the bytes back?
 
From: GG
Sent: Saturday, July 21, 2012 8:54 PM
Subject: Re: Having some trouble uploading photo
 

MarkB

unread,
Jul 23, 2012, 6:42:50 AM7/23/12
to tumbl...@googlegroups.com
You have to convert the image stream to a hex string escaping out any nonreserved char. i,e

public static string unreserved = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~";

any char not in the above string should be converted to its hex equiv.

Regards
Mark

GG

unread,
Jul 24, 2012, 7:48:31 PM7/24/12
to tumbl...@googlegroups.com
jsOauth already handles that.  It passes the binary data through:

    OAuth.urlEncode = function (string) {
        function hex(code) {
            var hex = code.toString(16).toUpperCase();
            if (hex.length < 2) {
                hex = 0 + hex;
            }
            return '%' + hex;
        }

        if (!string) {
            return '';
        }

        string = string + '';
        var reserved_chars = /[ \r\n!*"'();:@&=+$,\/?%#\[\]<>{}|`^\\\u0080-\uffff]/,
            str_len = string.length, i, string_arr = string.split(''), c;

        for (i = 0; i < str_len; i++) {
            if (c = string_arr[i].match(reserved_chars)) {
                c = c[0].charCodeAt(0);

                if (c < 128) {
                    string_arr[i] = hex(c);
                } else if (c < 2048) {
                    string_arr[i] = hex(192+(c>>6)) + hex(128+(c&63));
                } else if (c < 65536) {
                    string_arr[i] = hex(224+(c>>12)) + hex(128+((c>>6)&63)) + hex(128+(c&63));
                } else if (c < 2097152) {
                    string_arr[i] = hex(240+(c>>18)) + hex(128+((c>>12)&63)) + hex(128+((c>>6)&63)) + hex(128+(c&63));
                }
            }
        }

        return string_arr.join('');
    };
Reply all
Reply to author
Forward
0 new messages