0

I am having difficulties to download Image attachment from email.

Hello!

I am having difficulties to download Image attachment from email.

After executing :

HttpPost request = new HttpPost("http://mail.yahooapis.com/ya/download");
Method: DownloadAttachment
HttpResponse response = httpClient.execute(request);

I get valid(I believe) response. Here are the Headers of Response:

Date=Fri, 29 Oct 2010 21:49:33 GMT
P3P=policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
Vary=Accept-Encoding
Content-Type=text/html; charset=utf-8
Cache-Control=private
Age=5
Transfer-Encoding=chunked
Connection=keep-alive
Server=YTS/1.17.23

When I try to get InputStream from Response Entity to download file I am not getting anything.. sad.gif please advise me what am I doing wrong?


HttpEntity entity = response.getEntity();

if(entity!=null)
{
OutputStream fos = new FileOutputStream("target.jpg");
InputStream is = entity.getContent();
byte[] data = new byte[1024];
while((is.read(data)) > 0) {
fos.write(data);
}
is.close();
fos.close();
}

Thank you.

by
7 Replies
  • I got it working. The problem was that I was doing Post instead of Get. Silly me.

    Thank you.
    0
  • nice :)Thank you.
    0
  • I'm also having problems trying to download attachments. I keep getting an error 404.

    I'm doing a GET at: http://mail.yahooapis.com/ya/download
    with the parameters specified here: http://developer.yahoo.com/mail/docs/user_...Attachment.html

    What headers should I be sending for this request?

    I'm confused as I read above that it worked and now I'm stuck trying to download an attachment.

    Thanks.
    0
  • Even though I think I'm doing things right as I have been with the other endpoints.
    The Download endpoint is ending up to me trouble.

    Sample code would be very helpful
    Thank you.
    0
  • I'm confused, so the attachement is sent back in the header? Where in the header?

    I keep getting a read timeout --- if anyone knows how to do this in Perl, please help, thanks
    0
    • Aug 23, 2012
    Hello, 
    Could you please post a complete sample code, please...
    i have tried many scenarios but none of them do the work for me.


    please help :(

    QUOTE(Sergey @ 29 Oct 2010 11:16 PM)
    I got it working. The problem was that I was doing Post instead of Get. Silly me.

    Thank you.
    0
  • Hi friends! I solved the problem . Code below (params is an array like array('fid'=>'Test','mid'=>'2_0_0_21_22_AI...2QEY','pid'=>'1.2.2','clean'=>'0','inline'=>'0')) AND define('DL_ENDPOINT_URL', 'https://mail.yahooapis.com/ya/download'); Main "trick" is to sign the whole batch of GET-params (not only oauth* params). Hope, it will help.

                $ch = curl_init(DL_ENDPOINT_URL.'?'.http_build_query($params));
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                    $oaparams= array(
                        'oauth_nonce' => OAuthRequest::generate_nonce(),
                        'oauth_timestamp' => OAuthRequest::generate_timestamp(),
                        'oauth_version' => '1.0',
                        'oauth_signature_method' => 'HMAC-SHA1',
                        'oauth_consumer_key' => $this->oaConsumerKey,
                        'oauth_token' => $tok['oauth_token']
                    );
                    $request = new OAuthRequest('GET', DL_ENDPOINT_URL,array_merge($oaparams,$params));
    
                    $request->sign_request($this->signature, new OAuthConsumer('', $this->oaConsumerSecret), new OAuthToken('', $tok['oauth_token_secret']));
    
    
    
                    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                        'Accept: application/json',
                        $request->to_header()
                    ));
                    $rawresponse = curl_exec($ch);
                    $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                    $responseContentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);            
                    curl_close($ch);
    
    0
  • Recent Posts

    in Yahoo! Mail Web Services API