Abliamit
Abliamit

Reputation: 493

Email Migration API v2. Multipart insert returns 503

I testing Email Migration API V2 with google client api for ruby version 0.7.1 For multipart upload I always getting this response from server:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "backendError",
    "message": "Backend Error"
   }
  ],
  "code": 503,
  "message": "Backend Error"
 }
}

Here is my code:

client = Google::APIClient.new(
  :application_name => 'My app',
  :application_version => '1.1.0'
)
#auth code skipped

migration = client.discovered_api('admin', 'email_migration_v2')

file = {"isInbox" => true}
mail =  StringIO.new "Date: Wed, 03 Jan 2013 02:56:03 -0800
From: [email protected]
To: [email protected]
Subject: Hello World!
MIME-Version: 1.0
Content-Type: text/html; charset=windows-1252
Content-transfer-encoding: 8bit

And I think to myself... What a wonderful world!"

media = Google::APIClient::UploadIO.new(mail, 'message/rfc822')

client.execute!(:api_method=> migration.mail.insert,
  :media => media,
  :body_object => file,
  parameters: {
    'userKey' => "[email protected]",
    'uploadType' => 'multipart',
})

Some logs info

DEBUG 18:58:13 rails [pid=6311]: Google::APIClient::Request Sending API request post https://www.googleapis.com/upload/email/v2/users/[email protected]/mail?uploadType=multipart {"User-Agent"=>"My app/1.1.0 google-api-ruby-client/0.7.1 Mac OS X/10.9.4\n (gzip)", "Content-Type"=>"multipart/related;boundary=-----------RubyApiMultipartPost", "Content-Length"=>"682", "Accept-Encoding"=>"gzip", "Authorization"=>"Bearer xxxxx", "Cache-Control"=>"no-store"}

POST BODY:

DEBUG 18:58:13 rails [pid=6311]: -------------RubyApiMultipartPost
Content-Disposition: form-data; name=""; filename="file.json"
Content-Length: 16
Content-Type: application/json
Content-Transfer-Encoding: binary

{"isInbox":true}
-------------RubyApiMultipartPost
Content-Disposition: form-data; name=""; filename="local.path"
Content-Length: 249
Content-Type: message/rfc822
Content-Transfer-Encoding: binary

Date: Wed, 03 Jan 2013 02:56:03 -0800
From: [email protected]
To: [email protected]
Subject: Hello World!
MIME-Version: 1.0
Content-Type: text/html; charset=windows-1252
Content-transfer-encoding: 8bit

And I think to myself... What a wonderful world!
-------------RubyApiMultipartPost--

Please help me understand why google responds with 503. And how I can resolve it. I am sure that I didn't reach API quota.

Update 1:

Looks like Content-Disposition header is the reason of 503 error, Because without it upload works fine!

Upvotes: 1

Views: 168

Answers (0)

Related Questions