Uploading PDF's through the protocol

173 views
Skip to first unread message

Daniel Marashlian

unread,
Oct 16, 2009, 3:03:09 PM10/16/09
to Google Documents List API
Hi Eric,

I have 2 questions:

1. Is it possible to create a new/empty doc of type "PDF" in the same
way we use the protocol for documents, spreadsheets, and
presentations?

2. For Web-Applications (getting the file from the client's computer),
I had to take your suggestions and modify the C# API function:

public DocumentEntry UploadDocument(string fileName, string
documentName)

in that function, you pass in the filename (path to file on the user's
computer) and within the function there is code to get the stream of
that file:

FileInfo fileInfo = new FileInfo(fileName);
FileStream stream = fileInfo.Open(FileMode.Open, FileAccess.Read,
FileShare.ReadWrite);

so I created an overloaded function:

private static DocumentEntry UploadDocument(DocumentsService service,
byte[] bytes, string filename)

it takes in the DocumentsService service object to call
service.Insert, though as you see I pass in the bytes of the file (in
which I create a stream from). I needed to do this because from a web-
application, we don't have access to the user's computer, though
through the HTML file type input control, we can get the bytes of the
file.

But the issue I'm seeing is the Google Docs API is returning me an
error telling me it's an unsupported file type.

Any ideas?

Daniel Marashlian

unread,
Oct 16, 2009, 3:19:40 PM10/16/09
to Google Documents List API
Here's more information from the error messages for question 2 above:

Exception: {"Execution of request failed: http://docs.google.com/feeds/documents/private/full"}

Inner Exception: {"The remote server returned an error: (415)
Unsupported Media Type."}

Eric Bidelman

unread,
Oct 17, 2009, 9:22:13 PM10/17/09
to google-docum...@googlegroups.com
1. No, PDFs need content on creation time.

URI.  Change it to /feeds/default/...

-eric

Daniel Marashlian

unread,
Oct 19, 2009, 1:18:15 AM10/19/09
to Google Documents List API
HI Eric,

I changed the URL to "http://docs.google.com/feeds/default/private/
full" in my custom UploadDocument function.

and now it's giving me an error: {"Execution of request failed:
http://docs.google.com/feeds/default/private/full"}
inner exception: {"The remote server returned an error: (400) Bad
Request."}

here is my custom function:

private static DocumentEntry UploadDocument(DocumentsService service,
Stream stream, string filename)
{
Uri postUri = new Uri("http://docs.google.com/feeds/
default/private/full");

//convert the extension to caps and strip the "." off the
front
string ext = Path.GetExtension(filename).ToUpper
().Substring(1);

Hashtable GDocumentsAllowedTypes = new Hashtable();
GDocumentsAllowedTypes.Add("CSV", "text/csv");
GDocumentsAllowedTypes.Add("TAB", "text/tab-separated-
values");
GDocumentsAllowedTypes.Add("TSV", "text/tab-separated-
values");
GDocumentsAllowedTypes.Add("TXT", "text/plain");
GDocumentsAllowedTypes.Add("HTML", "text/html");
GDocumentsAllowedTypes.Add("HTM", "text/html");
GDocumentsAllowedTypes.Add("DOC", "application/msword");
GDocumentsAllowedTypes.Add("DOCX", "application/
vnd.openxmlformats-officedocument.wordprocessingml.document");
GDocumentsAllowedTypes.Add("ODS", "application/x-
vnd.oasis.opendocument.spreadsheet");
GDocumentsAllowedTypes.Add("ODT", "application/
vnd.oasis.opendocument.text");
GDocumentsAllowedTypes.Add("RTF", "application/rtf");
GDocumentsAllowedTypes.Add("SXW", "application/
vnd.sun.xml.writer");
GDocumentsAllowedTypes.Add("XLSX", "application/
vnd.openxmlformats-officedocument.spreadsheetml.sheet");
GDocumentsAllowedTypes.Add("XLS", "application/vnd.ms-
excel");
GDocumentsAllowedTypes.Add("PPT", "application/vnd.ms-
powerpoint");
GDocumentsAllowedTypes.Add("PPS", "application/vnd.ms-
powerpoint");
GDocumentsAllowedTypes.Add("PDF", "application/pdf");

string contentType = (String)GDocumentsAllowedTypes[ext];

if (contentType == null)
{
throw new ArgumentException("File extension '" + ext +
"' is not recognized as a valid GDoc extension.");
}

DocumentEntry entry = service.Insert(postUri, stream,
contentType, filename) as DocumentEntry;

stream.Close();

return entry;
}


how do I get this working so I can upload PDF files?

thanks!
Daniel

On Oct 17, 6:22 pm, Eric Bidelman <api.e...@google.com> wrote:
> 1. No, PDFs need content on creation time.
> 2.http://docs.google.com/feeds/documents/private/fullis a v2.0
> URI.  Change it to /feeds/default/...
>
> -eric
>

Eric Bidelman

unread,
Oct 19, 2009, 1:37:47 AM10/19/09
to google-docum...@googlegroups.com
I don't see a version header.

Daniel Marashlian

unread,
Oct 19, 2009, 1:59:01 AM10/19/09
to Google Documents List API
sweeeeeeeeettttttttttttttttttttttttttttttttt :)

On Oct 18, 10:37 pm, Eric Bidelman <api.e...@google.com> wrote:
> I don't see a version header.
>
> > > 2.http://docs.google.com/feeds/documents/private/fullisa v2.0

Seth Hillman

unread,
Nov 12, 2009, 8:45:25 AM11/12/09
to Google Documents List API
Can you post some code that fixed the version header issue? I am
getting the same error and I set the following in my UploadDocument
method:
this.ProtocolMajor = VersionDefaults.VersionTwo;

Thanks.
> > > > > > Any ideas?- Hide quoted text -
>
> - Show quoted text -

Seth Hillman

unread,
Nov 12, 2009, 9:41:20 AM11/12/09
to Google Documents List API
never mind. I set it to 3 and now it works.
> > - Show quoted text -- Hide quoted text -
Reply all
Reply to author
Forward
0 new messages