0

I'm trying to upload photo to Flickr using Scribe Library, But I've no idea how to use MultipartEntity in Java(I'm new to JAVA). The response from Flickr is: code=93, POST request is too large.

Here's my code, Kindly guide me in right direction.

                Bundle extras = data.getExtras(); 
                Bitmap pic = extras.getParcelable("data");
                ByteArrayOutputStream stream = new ByteArrayOutputStream();  
                stream.toByteArray();
                pic.compress(Bitmap.CompressFormat.JPEG, 100, stream);
                imageView.setImageBitmap(pic);

                 final OAuthService service = new ServiceBuilder()
                .provider(FlickrApi.class)
                .apiKey(APIKEY)
                .apiSecret(APISECRET).callback(CALLBACK)
                .build();

                OAuthRequest request = new OAuthRequest(Verb.POST, "http://api.flickr.com/services/upload/");


                byte[] img = stream.toByteArray();
                MultipartEntity entity = new MultipartEntity();
                ContentBody body= new ByteArrayBody(stream.toByteArray(),"pic.jpg");
                entity.addPart("photo",body);
                request.addPayload(img);
                request.addHeader(entity.getContentType().getName(), entity.getContentType().getValue());

                service.signRequest(accessToken, request);
                Response response = request.send();
                String rbody=response.getBody();
Desire
  • 563
  • 4
  • 13
  • 28
  • when it says the request is too large, does it by chance work with small images? – Axarydax Mar 31 '13 at 16:25
  • i'm not sure my above code is correct! – Desire Mar 31 '13 at 16:26
  • I am not sure too, but you should investigate if the problem is on your side or on Flickr's side - if the error message says request too large, try it with a smaller request with smallish image, so you can eliminate that possiblity. – Axarydax Mar 31 '13 at 16:28

1 Answers1

0

From the API documentation of Flickr(http://www.flickr.com/services/api/upload.api.html)

Note that the 'photo' parameter should not be included in the signature. All other POST parameters should be included when generating the signature.

But in your code you have even used the "photo" part while generating the signature. Try generating the signature without the "photo" part and than after signing the request add "photo" parameter.

The error reported by Flickr could be caused when Flickr will try to validate the signature and would find signature to be above its maximum allowed length.