YouTube API Browser Upload Failing with 500 Internal Error - youtube

https://gdata.youtube.com/action/GetUploadToken used to work just fine but has now stopped working and returns a 500 error everytime, unless the Authorization token has timed out, Then it gets an "Authorize = true" back. So the server is responding and can tell me when my token is no longer any good. Uses OAUth2 and I hve no problem getting a token. Any ideas?
** Headers Sent **
[headers] => array(
[Authorization] => Bearer ********
[X-GData-Key] => key=*************
[GData-Version] => 2
[Content-Type] => application/atom+xml; charset=UTF-8
)
** Body sent **
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007">
<media:group>
<media:title type="plain">Wildlife</media:title>
<media:description type="plain">Wildlife</media:description>
<media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">Travel</media:category>
<media:keywords>wildlife</media:keywords>
<media:license type="text/html"/>
</media:group>
</entry>
** Response data **
Array
(
[headers] => Array
(
[x-gdata-user-country] => US
[content-type] => text/html; charset=UTF-8
[date] => Sat, 10 Nov 2012 15:45:34 GMT
[expires] => Sat, 10 Nov 2012 15:45:34 GMT
[cache-control] => private, max-age=0
[x-content-type-options] => nosniff
[x-frame-options] => SAMEORIGIN
[x-xss-protection] => 1; mode=block
[server] => GSE
)
[body] => <HTML>
<HEAD>
<TITLE>Internal Error</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Internal Error</H1>
<H2>Error 500</H2>
</BODY>
</HTML>
[response] => Array
(
[code] => 500
[message] => Internal Server Error
)
[cookies] => Array
(
)
)

Related

Excon::Error::RequestEntityTooLarge: Expected(200) <=> Actual(413 Request Entity Too Large) : Fog google storage ruby

I have a rails app 5.2, ruby 2.3.4 with fog-google (1.3.3).
It was working great on dev, test and prod environnement since a long time to upload and download file.
But now fog storage refuse to upload file.
If i'm oppening a rails c and put
config = Rails.application.config.x.settings["cloud_storage"]
fogStorage = Fog::Storage.new(
provider: "Google",
google_storage_access_key_id: config["access_key_id"],
google_storage_secret_access_key: config["secret_access_key"]
)
storageBucket = fogStorage.directories.new key: config["bucket"]
file_name = File.join(Rails.root,"DSC00174.jpg")
file = File.open(file_name, "r")
image = storageBucket.files.new(
key: "logo_client_image_test/AAA.jpg",
body: file.read,
public: true
content_type:'image/jpeg'
)
image.save
puts image.public_url
I got this message
Excon::Error::RequestEntityTooLarge: Expected(200) <=> Actual(413 Request Entity Too Large)
excon.error.response
:body => "<!DOCTYPE html>\n<html lang=en>\n <meta charset=utf-8>\n <meta name=viewport content=\"initial-scale=1, minimum-scale=1, width=device-width\">\n <title>Error 413 (Request Entity Too Large)!!1</title>\n <style>\n *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}#media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}#media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}#media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}\n </style>\n <a href=//www.google.com/><span id=logo aria-label=Google></span></a>\n <p><b>413.</b> <ins>That\xE2\x80\x99s an error.</ins>\n <p>Your client issued a request that was too large.\n <script>\n (function() { var c=function(a,d,b){a=a+\"=deleted\"+(\"; path=\"+d);null!=b&&(a+=\"; domain=\"+b);document.cookie=a+\"; expires=Thu, 01 Jan 1970 00:00:00 GMT\"};var g=function(a){var d=e,b=location.hostname;c(d,a,null);c(d,a,b);for(var f=0;;){f=b.indexOf(\".\",f+1);if(0>f)break;c(d,a,b.substring(f+1))}};var h;if(4E3<unescape(encodeURI(document.cookie)).length){for(var k=document.cookie.split(\";\"),l=[],m=0;m<k.length;m++){var n=k[m].match(/^\\s*([^=]+)/);n&&l.push(n[1])}for(var p=0;p<l.length;p++){var e=l[p];g(\"/\");for(var q=location.pathname,r=0;;){r=q.indexOf(\"/\",r+1);if(0>r)break;var t=q.substring(0,r);g(t);g(t+\"/\")}\"/\"!=q.charAt(q.length-1)&&(g(q),g(q+\"/\"))}h=!0}else h=!1;\nh&&setTimeout(function(){if(history.replaceState){var a=location.href;history.replaceState(null,\"\",\"/\");location.replace(a)}},1E3); })();\n\n</script>\n <ins>That\xE2\x80\x99s all we know.</ins>\n"
:cookies => [
]
:headers => {
"Content-Length" => "2398"
"Content-Type" => "text/html; charset=UTF-8"
"Date" => "Thu, 19 Jul 2018 10:11:50 GMT"
"Referrer-Policy" => "no-referrer"
}
:host => "locabri.storage.googleapis.com"
:local_address => "192.168.1.44"
:local_port => 51136
:path => "/logo_client_image_test%2FAAADSC00174.jpg"
:port => 443
:reason_phrase => "Request Entity Too Large"
:remote_ip => "216.58.206.240"
:status => 413
:status_line => "HTTP/1.0 413 Request Entity Too Large\r\n"
The file size is 98ko.
I can transfert the file manually to the google bucket with the online interface.
The only change I've done recently is to upgrade Rails to 5.2. and config file haven't change.
I found the solution by myself. In rails 5.2 body has to be file not file.read
image = storageBucket.files.new(
key: "logo_client_image_test/AAA.jpg",
body: file,
public: true
content_type:'image/jpeg'
)
Posted on behalf of the question asker

Sending mail with embedded image in Ruby

I want to send a mail with an attached image and embed this image in html. As a source for tag , What should I write and is there any missing header parts such a content_type ?
When I am doing real test, I send to a mail to my gmail account. I can see there is an attachment with name "unnamed" and I could not display image even when I download.
Gem: Pony
require 'pony'
Pony.override_options = { :via => :test }
Pony.mail(
:to => 'foo#bar',
:from => 'abc#abc.com',
:subject => 'test123',
:body => "<h1><strong>Dear X, check the newsletter ,<br></strong></h1> <img src='attached image' />",
:attachments => {"happy_image.jpg" => File.read("happy_image.jpg")}
)
puts Mail::TestMailer.deliveries
output:
Date: Tue, 06 Dec 2016 17:23:05 +0300
From: abc#abc.com
To: foo#bar
Message-ID: <5846c9ca183d6_5983c9fd899060#MW7BIQ12TKYHQC.mail>
Subject: test123
Mime-Version: 1.0
Content-Type: multipart/mixed;
boundary="--==_mimepart_5846c9caf15a_5983c9fd8989e5";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_5846c9caf15a_5983c9fd8989e5
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<h1><strong>Dear X, check the newsletter ,<br></strong></h1> <img src='' />
----==_mimepart_5846c9caf15a_5983c9fd8989e5
Content-Type: image/jpeg;
filename=happy_image.jpg
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename=happy_image.jpg
Content-ID: <happy_image.jpg#MW7BIQ12TKYHQC>
/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQE
BQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/
2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU
FBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCAHiAuMDASIAAhEBAxEB/8QA
HwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUF
BAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkK
FhcYGQ==
----==_mimepart_5846c9caf15a_5983c9fd8989e5--
You should be able to BASE64 encode the image, and use the resulting string as the src of the img tag.
For example:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWQAAAD8CAYAAAB..."/>
Also make sure that your content type is set as text/html instead of text/plain. Looking at the mail, it seems that it's set to the latter, hence why images don't render and tags render as text. Add the following to your arguments to use text/html content type:
:headers => { 'Content-Type' => 'text/html' }

Attachment not sent properly in rails using ActionMailer

I am trying to send xls file via ActionMailer.
mailer = ActionMailer::Base.mail(:to => "reciever#gmail.com", :from => "sender#gmail.com", :content_type=>"application/vnd.ms-excel", :body=> '')
mailer.attachments['filename.xls']= {mime_type: 'application/vnd.ms-excel', content: File.read("filePath.xls")}
mailer.deliver!
I am able to receive the mail as well.
But somehow the attachment is not correct, it shows up as noname and below is the content I get in the file (I am copy pasting the exact contents)
--
Date: Wed, 04 Jun 2014 23:33:48 +0530
Mime-Version: 1.0
Content-Type: application/vnd.ms-excel;
charset=UTF-8
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename=filename.xls
Content-ID: <538f5f82836992#C02L2178FFT3.gmail>
PGgzIHN0eWxlPSJmb250LXdlaWdodDpib2xkIj4gCiAgICBTaG93aW5nCiAg
ICBvcGVuCiAgICByZXF1ZXN0cwogICAgZnJvbQogICAgTm92IDIxLCAyMDEz
....
I am sure I am missing something simple, I am unable to figure out what. Can someone help?
Try this:--
mailer = ActionMailer::Base.mail(:to => "reciever#gmail.com", :from => "sender#gmail.com", :content_type=>"application/vnd.ms-excel", :body=> '')
mailer.attachments["filename.xls"]= File.read("filePath.xls")
mailer.deliver!

How to STOP caches_page from setting page in cache permanently? -- Rails 3.1

I want to make sure that if the file changes (if cache files are deleted for example), the user's browser shouldn't load the cached version.
Here is the issue I found. Here are the headers when I DON'T use caches_page:
HTTP/1.1 200 OK =>
ETag => "4ff902bc57e1892d7a963e43bf56dcc8"
X-UA-Compatible => IE=Edge,chrome=1
Cache-Control => max-age=0, private, must-revalidate
X-Runtime => 2.710376
X-Rack-Cache => miss
Set-Cookie => _Myapp_session=.....; path=/; HttpOnly
Status => 200
And here are the headers when I do use it:
HTTP/1.1 200 OK =>
ETag => "80003-1ad93-4b44a71a41180"
Last-Modified => Sat, 17 Dec 2011 14:22:14 GMT
Accept-Ranges => bytes
I've removed the common lines for easy comparison.
Are there any issues with these differing headers?
I didn't find any rails way to do this so put in "Header set" directives in apache.conf

OAuth with Digg API

I'm attempting to get Rails to play nice with the Digg API's OAuth. I'm using the oauth gem (ruby one, not the rails one).
My code looks approximately like this:
#consumer = OAuth::Consumer.new(API_KEY, API_SECRET,
:scheme => :header,
:http_method => :post,
:oauth_callback => "http://locahost:3000",
:request_token_url => 'http://services.digg.com/1.0/endpoint?method=oauth.getRequestToken',
:access_token_url => 'http://services.digg.com/1.0/endpoint?method=oauth.getAccessToken',
:authorize_url => 'http://digg.com/oauth/authorize')
#request_token = DiggController.consumer.get_request_token({
:oauth_callback => "http://xx.xxx.xxx.x:3000/digg/callback"
}, {
'Content-Type' => 'application/x-www-form-urlencoded'
})
session[:request_token] = #request_token.token
session[:request_token_secret] = #request_token.secret
redirect_to #request_token.authorize_url
Which is by-the-book in terms of what the gem documentation gave me. However, Digg spits a "400 Bad Request" error back at me when #consumer.get_request_token is called. I can't figure out what I'm doing wrong. Any ideas?
Edit: Code updated and Wireshark output added. My error is now "401 Authorization Required".
Output from Wireshark:
POST /1.0/endpoint?method=oauth.getRequestToken HTTP/1.1
Accept: */*
Connection: close
User-Agent: OAuth gem v0.3.6
Content-Type: application/x-www-form-urlencoded
Authorization: OAuth oauth_nonce="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
oauth_callback="http%3A%2F%2Fxx.xxx.xxx.x%3A3000%2Fdigg%2Fcallback",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="1268687137",
oauth_consumer_key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
oauth_signature="xxx%2Bxxxxxxxxxxxxxxx%2Fxxxxxxx%3D", oauth_version="1.0"
Content-Length: 48
Host: services.digg.com
Content-Type=application%2fx-www-form-urlencoded
HTTP/1.1 401 Authorization Required
Date: Mon, 15 Mar 2010 21:05:37 GMT
Server: Apache
X-Powered-By: PHP/5.2.9-digg8
Cache-control: private
X-RateLimit-Current: 1
X-RateLimit-Max: 1000
X-RateLimit-Reset: 3600
X-Digg-Api-Version: 1.0
Accept-Ranges: bytes
Content-Length: 111
Keep-Alive: timeout=5, max=9998
Connection: Keep-Alive
Content-Type: text/xml;charset=utf-8
<?xml version="1.0" encoding="UTF-8"?>
<error code="5001" message="Invalid
signature" timestamp="1268687137"/>
Incidentally, the callback parameter should not be localhost:3000 but rather your public IP address (making sure to also open up port 3000 for external connections in your computer and/or router firewall(s)), or be left to the default (out-of-band.)
Examine the contents of the OAuth::Unauthorized exception which gets thrown (or use a sniffer such as tcpdump or Wireshark) to get additional details about the HTTP 400 error (they are probably having issues with some of your parameters.)

Resources