Dear Eric,

    Everything is fine except HTTP status is 400.
    Besides, may I know what MIME type should I set when uploading PDF
files.
    (.doc is set for "document", how about .pdf?)

Best Regards,
Allen

On 5月22日, 下午12時22分, "Eric (Google)" <api.e...@google.com> wrote:
> Hi Allen,
>
> What error are you getting?  Can you provide
> an HTTP header/reponse capture?
>
> Eric
>
> On May 11, 12:10 am, Allen <allenwlhu...@gmail.com> wrote:
>
> > Dear all,
>
> >     I can upload any text files(text/csv, text/htm, text/html, text/
> > tab, text/txt, text/tsv), but can not upload application files(such as
> > application/pdf, application/msword, application/vnd.ms-powerpoint,
> > and application/vnd.ms-excel) to Google docs.
>
> >     My way is to read the file's content to a air.fileStream that
> > stored into a string, and then send it to Google. It can works when
> > file is a .txt, but .doc can not.
>
> >     Does anyone know what's worng it is? The followings are my code,
>
> >         var fileToOpen = air.File.documentsDirectory;
> >         var filePath = null;
> >         var fileStream = new air.FileStream();
> >         var x;
> >         var contents = null;
> >         var filename = null;
> >         var filetype = null;
> >         var filelength = null;
> >         var extensionDesc = null;
>
> >         function selectTextFile(root)
> >         {
> >              root.browseForOpen("Open", new window.runtime.Array);
> >              root.addEventListener(air.Event.SELECT, fileSelected);
> >         }
> >         function fileSelected(event)
> >         {
> >             filePath = fileToOpen.nativePath;
> >                 alert (filePath);
> >                 x =new air.File(filePath);
> >                 filename = x.name;
> >                 filetype = x.type;
> >                 filelength = x.size;
> >                 filetype = filetype.substring(1);
> >                 fileStream.openAsync(x, air.FileMode.READ);
> >                 fileStream.addEventListener(air.Event.COMPLETE, 
> > completeHandler);
> >         }
> >         function completeHandler(event)
> >         {
> >                 contents = fileStream.readMultiByte( 
> > fileStream.bytesAvailable,
> > "iso-8859-1" );
> >                 fileStream.close();
> >                 filehandle();
> >                 UploadFromServer();
> >         }
> >         function filehandle(){
> >                 extensionDesc = FILE_EXTENSIONS[filetype];
> >         }
> >         var FILE_EXTENSIONS = {
> >           'csv': {
> >             mime: 'text/csv',
> >             type: Document.SPREADSHEET },
> >           'doc': {
> >             mime: 'application/msword',
> >             type: Document.DOCUMENT },
> >           'htm': {
> >             mime: 'text/html',
> >             type: Document.DOCUMENT },
> >           'html': {
> >             mime: 'text/html',
> >             type: Document.DOCUMENT },
> >           'ods': {
> >             mime: 'application/x-vnd.oasis.opendocument.spreadsheet',
> >             type: Document.SPREADSHEET },
> >           'odt': {
> >             mime: 'application/vnd.oasis.opendocument.text',
> >             type: Document.DOCUMENT },
> >           'pdf': {
> >             mime: 'application/pdf',
> >             type: Document.DOCUMENT },
> >           'pps': {
> >             mime: 'application/vnd.ms-powerpoint',
> >             type: Document.PRESENTATION },
> >           'ppt': {
> >             mime: 'application/vnd.ms-powerpoint',
> >             type: Document.PRESENTATION },
> >           'rtf': {
> >             mime: 'application/rtf',
> >             type: Document.DOCUMENT },
> >           'sxw': {
> >             mime: 'application/vnd.sun.xml.writer',
> >             type: Document.DOCUMENT },
> >           'tab': {
> >             mime: 'text/tab-separated-values',
> >             type: Document.SPREADSHEET },
> >           'txt': {
> >             mime: 'text/plain',
> >             type: Document.DOCUMENT },
> >           'tsv': {
> >             mime: 'text/tab-separated-values',
> >             type: Document.SPREADSHEET },
> >           'xls': {
> >             mime: 'application/vnd.ms-excel',
> >             type: Document.SPREADSHEET }
> >         };
>
> >         function UploadFromServer(){
>
> >                 var xmlReq = new XMLHttpRequest();
> >                 var url = 
> > "https://docs.google.com/feeds/documents/private/full";;
> >                 xmlReq.open("POST", url, true);
>
> >                 xmlReq.setRequestHeader('Authorization', 'GoogleLogin 
> > auth=' +
> > authToken);
> >                 xmlReq.setRequestHeader('Content-Length', filelength);
> >                 xmlReq.setRequestHeader('Content-Type', extensionDesc.mime);
> >                 xmlReq.setRequestHeader('Slug', filename);
>
> >                 try {
> >                         xmlReq.send(contents);
> >                 }
> >                 catch (e) {
> >                         }
> >         }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Docs Data APIs" group.
To post to this group, send email to Google-Docs-Data-APIs@googlegroups.com
To unsubscribe from this group, send email to 
google-docs-data-apis+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Docs-Data-APIs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to