diff --git a/src/drive/Drive.cc b/src/drive/Drive.cc index 50e4942..938ff7b 100644 --- a/src/drive/Drive.cc +++ b/src/drive/Drive.cc @@ -200,7 +200,7 @@ std::cout << "downloading " << path << std::endl ; else { std::cout << "local " << filename << " is newer" << std::endl ; -// UploadFile( entry ) ; + UploadFile( entry ) ; } } } @@ -208,45 +208,43 @@ std::cout << "local " << filename << " is newer" << std::endl ; void Drive::UploadFile( const Json& entry ) { -// std::cout << "entry:\n" << entry << std::endl ; + std::string meta = + "" + "" + "" + "Grive Document" + "" ; - Json resume_link = entry["link"].FindInArray( "rel", - "http://schemas.google.com/g/2005#resumable-edit-media" )["href"] ; - std::cout << resume_link.As() << std::endl ; - http::Headers hdr( m_http_hdr ) ; - hdr.push_back( "Expect:" ) ; - hdr.push_back( "If-Match: *" ) ; - hdr.push_back( "X-Upload-Content-Length: 29" ) ; + hdr.push_back( "Slug: Grive Document" ) ; hdr.push_back( "X-Upload-Content-Type: text/plain" ) ; + hdr.push_back( "X-Upload-Content-Length: 10" ) ; - std::istringstream resp( http::Put( resume_link.Get(), "", hdr ) ) ; + std::string resp = http::PostDataWithHeader( + "https://docs.google.com/feeds/upload/create-session/default/private/full?convert=false", + "", + m_http_hdr ) ; + + std::cout << "resp " << resp ; + std::istringstream ss( resp ) ; std::string line ; - while ( std::getline( resp, line ) ) + while ( std::getline( ss, line ) ) { - // find the location header static const std::string location = "Location: " ; if ( line.substr( 0, location.size() ) == location ) { - std::string upload_uri = line.substr( location.size() ) ; - upload_uri = upload_uri.substr( 0, upload_uri.size() - 1 ) ; - std::cout << upload_uri << std::endl ; + std::string uplink = line.substr( location.size() ) ; + uplink = uplink.substr( 0, uplink.size() -1 ) ; - std::string upload_content = "this is the new text file!!!!" ; + std::string data( 10, '!' ) ; + http::Headers uphdr ; + uphdr.push_back( "Content-Type: text/plain" ) ; + uphdr.push_back( "Content-Range: bytes 0-9/10" ) ; - std::ostringstream content_range ; - content_range << "Content-Range: 0-" << upload_content.size()-1 << '/' << upload_content.size() ; - - http::Headers upload_hdr/*( m_http_hdr )*/ ; - upload_hdr.push_back( "Expect:" ) ; - upload_hdr.push_back( "Accept:" ) ; - upload_hdr.push_back( "Host:" ) ; -// upload_hdr.push_back( "Content-Type: text/plain" ) ; - upload_hdr.push_back( content_range.str() ) ; - - std::string resp2 = http::Put( upload_uri, upload_content, upload_hdr ) ; - std::cout << resp2 << std::endl ; + std::string resp = http::Put( uplink, data, uphdr ) ; + std::cout << "put response = " << resp << std::endl ; } } } diff --git a/src/protocol/HTTP.cc b/src/protocol/HTTP.cc index e084f3f..f030a9e 100644 --- a/src/protocol/HTTP.cc +++ b/src/protocol/HTTP.cc @@ -166,6 +166,24 @@ std::string PostData( const std::string& url, const std::string& data, const Hea curl_easy_setopt(curl, CURLOPT_POST, 1L); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, &post_data[0] ) ; curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, post_data.size() ) ; + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1 ) ; + + DoCurl( curl ) ; + return resp; +} + +std::string PostDataWithHeader( const std::string& url, const std::string& data, const Headers& hdr ) +{ + std::string resp ; + CURL *curl = InitCurl( url, &resp, hdr ) ; + + std::string post_data = data ; + + curl_easy_setopt(curl, CURLOPT_POST, 1L); + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, &post_data[0] ) ; + curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, post_data.size() ) ; + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L ) ; + curl_easy_setopt(curl, CURLOPT_HEADER, 1L ); DoCurl( curl ) ; return resp; diff --git a/src/protocol/HTTP.hh b/src/protocol/HTTP.hh index 107f2ef..df53a1e 100644 --- a/src/protocol/HTTP.hh +++ b/src/protocol/HTTP.hh @@ -43,6 +43,10 @@ namespace gr { namespace http const std::string& url, const std::string& data, const Headers& hdr = Headers() ) ; + std::string PostDataWithHeader( + const std::string& url, + const std::string& data, + const Headers& hdr = Headers() ) ; std::string PostFile( const std::string& url, const std::string& filename,