diff --git a/src/drive/Drive.cc b/src/drive/Drive.cc
index 6d7db36..3e6aec5 100644
--- a/src/drive/Drive.cc
+++ b/src/drive/Drive.cc
@@ -215,30 +215,40 @@ std::cout << "downloading " << path << std::endl ;
else
{
std::cout << "local " << filename << " is newer" << std::endl ;
- UploadFile( entry ) ;
+ // re-reading the file
+ ifile.seekg(0) ;
+
+ UploadFile( entry, filename, ifile.rdbuf() ) ;
}
}
}
}
-void Drive::UploadFile( const Json& entry )
+void Drive::UploadFile( const Json& entry, const std::string& filename, std::streambuf *file )
{
-/* std::string meta =
- ""
+ std::string meta =
+ "\n"
""
- ""
- "Test document"
+ "" + filename + ""
"" ;
-*/
+
+ std::string data(
+ (std::istreambuf_iterator(file)),
+ (std::istreambuf_iterator()) ) ;
+
+ std::ostringstream content_len ;
+ content_len << data.size() ;
+
http::Headers hdr( m_http_hdr ) ;
// hdr.push_back( "Slug: Grive Document" ) ;
-// hdr.push_back( "Content-Type: application/atom+xml" ) ;
+ hdr.push_back( "Content-Type: application/atom+xml" ) ;
hdr.push_back( "X-Upload-Content-Type: text/plain" ) ;
- hdr.push_back( "X-Upload-Content-Length: 1000" ) ;
+ hdr.push_back( "X-Upload-Content-Length: " + content_len.str() ) ;
hdr.push_back( "Expect:" ) ;
-/*
- std::string resp = http::PostDataWithHeader(
+
+/* std::string resp = http::PostDataWithHeader(
m_resume_link + "?convert=false",
meta,
hdr ) ;
@@ -247,11 +257,11 @@ void Drive::UploadFile( const Json& entry )
"http://schemas.google.com/g/2005#resumable-edit-media" )["href"] ;
std::cout << resume_link.As() << std::endl ;
- std::string etag = entry["gd$etag"].As() ;
- std::cout << "etag = " << etag << std::endl ;
+ std::string etag = entry["gd$etag"].As() ;
+ std::cout << "etag = " << etag << std::endl ;
hdr.push_back( "If-Match: " + etag ) ;
- std::string resp = http::Put( resume_link.Get(), "", hdr ) ;
+ std::string resp = http::Put( resume_link.Get(), meta, hdr ) ;
std::cout << "resp " << resp << std::endl ;
std::istringstream ss( resp ) ;
@@ -265,10 +275,9 @@ void Drive::UploadFile( const Json& entry )
std::string uplink = line.substr( location.size() ) ;
uplink = uplink.substr( 0, uplink.size() -1 ) ;
- std::string data( 1000, 'x' ) ;
http::Headers uphdr ;
uphdr.push_back( "Content-Type: text/plain" ) ;
- uphdr.push_back( "Content-Range: bytes 0-999/1000" ) ;
+// uphdr.push_back( "Content-Range: bytes 0-999/1000" ) ;
uphdr.push_back( "Expect:" ) ;
uphdr.push_back( "Accept:" ) ;
diff --git a/src/drive/Drive.hh b/src/drive/Drive.hh
index c88113e..8117697 100644
--- a/src/drive/Drive.hh
+++ b/src/drive/Drive.hh
@@ -41,7 +41,7 @@ public :
private :
void UpdateFile( const Json& entry ) ;
- void UploadFile( const Json& entry ) ;
+ void UploadFile( const Json& entry, const std::string& filename, std::streambuf *file ) ;
std::string Parent( const Json& entry ) ;
void ConstructDirTree( const std::vector& entries ) ;
diff --git a/src/protocol/OAuth2.cc b/src/protocol/OAuth2.cc
index 0e86db9..8026355 100644
--- a/src/protocol/OAuth2.cc
+++ b/src/protocol/OAuth2.cc
@@ -74,7 +74,8 @@ std::string OAuth2::MakeAuthURL(
Escape( "https://www.googleapis.com/auth/userinfo.profile" ) + "+" +
Escape( "https://docs.google.com/feeds/" ) + "+" +
Escape( "https://docs.googleusercontent.com/" ) + "+" +
- Escape( "https://spreadsheets.google.com/feeds/" ) +
+ Escape( "https://spreadsheets.google.com/feeds/" ) + "+" +
+ Escape( "https://www.googleapis.com/auth/drive.file/" ) +
"&redirect_uri=urn:ietf:wg:oauth:2.0:oob"
"&response_type=code"
"&client_id=" + client_id ;