Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 40 additions & 35 deletions libgrive/src/drive/Resource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -582,41 +582,46 @@ bool Resource::Upload(
bool post)
{
assert( http != 0 ) ;

File file( Path() ) ;
std::ostringstream xcontent_len ;
xcontent_len << "X-Upload-Content-Length: " << file.Size() ;

http::Header hdr ;
hdr.Add( "Content-Type: application/atom+xml" ) ;
hdr.Add( "X-Upload-Content-Type: application/octet-stream" ) ;
hdr.Add( xcontent_len.str() ) ;
hdr.Add( "If-Match: " + m_etag ) ;
hdr.Add( "Expect:" ) ;

std::string meta = (boost::format( xml_meta )
% m_kind
% xml::Escape(m_name)
).str() ;

http::StringResponse str ;
if ( post )
http->Post( link, meta, &str, hdr ) ;
else
http->Put( link, meta, &str, hdr ) ;

http::Header uphdr ;
uphdr.Add( "Expect:" ) ;
uphdr.Add( "Accept:" ) ;

// the content upload URL is in the "Location" HTTP header
std::string uplink = http->RedirLocation() ;
http::XmlResponse xml ;

http->Put( uplink, &file, &xml, uphdr ) ;
AssignIDs( Entry( xml.Response() ) ) ;
m_mtime = Entry(xml.Response()).MTime();

try {
File file( Path() ) ;
std::ostringstream xcontent_len ;
xcontent_len << "X-Upload-Content-Length: " << file.Size() ;

http::Header hdr ;
hdr.Add( "Content-Type: application/atom+xml" ) ;
hdr.Add( "X-Upload-Content-Type: application/octet-stream" ) ;
hdr.Add( xcontent_len.str() ) ;
hdr.Add( "If-Match: " + m_etag ) ;
hdr.Add( "Expect:" ) ;

std::string meta = (boost::format( xml_meta )
% m_kind
% xml::Escape(m_name)
).str() ;

http::StringResponse str ;
if ( post )
http->Post( link, meta, &str, hdr ) ;
else
http->Put( link, meta, &str, hdr ) ;

http::Header uphdr ;
uphdr.Add( "Expect:" ) ;
uphdr.Add( "Accept:" ) ;

// the content upload URL is in the "Location" HTTP header
std::string uplink = http->RedirLocation() ;
http::XmlResponse xml ;

http->Put( uplink, &file, &xml, uphdr ) ;
AssignIDs( Entry( xml.Response() ) ) ;
m_mtime = Entry(xml.Response()).MTime();
}
catch (gr::Exception& exc)
{
Log( "cannot upload: Exception %s", exc.what(), gr::log::critical) ;
return false;
}
return true ;
}

Expand Down