RGoogleDocs (version 0.7-0)

uploadDoc: Add or remove a document

Description

These functions allow the caller to manipulate the collection of documents in the Google Docs account. One can upload a document from the local machine. And one can remove or delete a document from the remote repository.

Usage

uploadDoc(content, con, name, type = as.character(findType(content)), binary = FALSE, asText = FALSE, folder = NULL, replace = TRUE, ...) deleteDoc(doc, con = getConnection(auth), auth = getGoogleAuth(), ...)

Arguments

content
the name of a local file or the actual content of a document to be uploaded.
doc
the name of the Google document to be removed.
con
the CURL connection to the Google Docs API which has been authenticated. See getGoogleDocsConnection.
name
the name of the new document to be created (or the document to be replaced).
type
the type of document. This can be the MIME type (e.g. "text/csv") or the short hand, e.g. "csv", "odt", ..., capitalized or uncapitalized. The type is matched in the vector DocTypeExtensions. The caller can pass the value as an "AsIs" object, i.e. type = I("text/kml") and the type will not be matched against DocTypeExtensions. The server wil still validate the type. So this is a way of using a new type recognized by Google Docs that is not reflected in the code in this package.
binary
a logical value indicating whether the content being uploaded is binary or not.
asText
a logical indicating whether the value of content is to be treated as the content to be uploaded (TRUE) or the name of a file (FALSE).
...
additional arguments to be passed to the curlPerform call.
auth
the auth token returned from a call to getGoogleAuth and used to initialize a connection.
folder
the identifier for a Google Folder. This should be a GoogleFolder object, e.g., returned via getDocs. Alternatively, it can be the name of a folder and this function will call getDocs itself to obtain the folder information. Finally, it can be the URL for the folder's content, i.e. the value of the "src" element of the content slot in a GoogleFolder object. This is the /feeds/folders/... URL. To specify the folder in this way, one must use the AsIs function I to identify the content as being the URL.
replace
a logical value. If this is TRUE, we check if there is an existing document named name. If there is, we rename it to a temporary name and attempt the upload of the new document in content. If this succeeds, the earlier document is removed. If the upload fails, the earlier document is moved back to the original name and so nothing is lost. If replace is FALSE, none of this is done and Google Docs allows documents with the same name in the same folder.

Value

uploadDoc returns an object of class GoogleDocument describing the newly uploaded document.deleteDoc returns 0 if the operation succeeded or a CURL error if it failed.

See Also

getGoogleDocsConnection

Examples

Run this code

if(exists("GoogleDocsPassword")) {
          # getGoogleDocsConnection("my login", "my password")

  con = getGoogleDocsConnection(names(GoogleDocsPassword), GoogleDocsPassword)

  x = "1, 2, 3\n4, 5, 6\n"
  uploadDoc(x, con, name = "direct csv", type = "csv")

  deleteDoc("Untitled Presentation", con)

  # uploading to a folder

     # Specify the folder object
  docs = getDocs(con)
  uploadDoc(x, con, name = "boo", type = "csv", folder = docs$MyFolder)

  f = docs$MyFolder
  f[["boo1", type = 'csv']] = x

     # We'll have to lookup the folder id in the call.
  uploadDoc(x, con, name = "boo2", type = "csv", folder = "MyFolder")

    # Give the explicit URL directly
  uploadDoc(x, con, name = "boo3", type = "csv", folder = I(docs$MyFolder@content["src"]))
}

Run the code above in your browser using DataLab