@@ -51,7 +51,7 @@ func uploadFile(filePath string, uploadStatus chan GuppyStatus) {
5151 // TODO: pick mimetype based on file extension
5252 f := & drive.File {
5353 Name : filepath .Base (filePath ),
54- MimeType : "application/vnd.google-apps.spreadsheet" ,
54+ MimeType : mapMimeTypeToGoogleMimeType ( mimeType ) ,
5555 }
5656
5757 createdFile , err := driveService .Files .Create (f ).Media (file , googleapi .ContentType (mimeType )).Fields ("webViewLink" ).Do ()
@@ -71,7 +71,7 @@ func uploadFile(filePath string, uploadStatus chan GuppyStatus) {
7171 "auth" : "cached|new" ,
7272 "duration" : 0 ,
7373 "file_size_kb" : 100 ,
74- "file_type" : "csv" ,
74+ "file_type" : mimeType ,
7575 })
7676}
7777
@@ -83,3 +83,23 @@ func getMimeType(filePath string) string {
8383 mimeType := mime .TypeByExtension (ext )
8484 return mimeType
8585}
86+
87+ func mapMimeTypeToGoogleMimeType (mimeType string ) string {
88+ // Map the MIME type to the Google MIME type
89+ switch mimeType {
90+ case "text/csv" :
91+ return "application/vnd.google-apps.spreadsheet"
92+ case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" :
93+ return "application/vnd.google-apps.spreadsheet"
94+ case "text/plain" :
95+ return "application/vnd.google-apps.document"
96+ case "application/pdf" :
97+ return "application/vnd.google-apps.document"
98+ case "application/vnd.openxmlformats-officedocument.wordprocessingml.document" :
99+ return "application/vnd.google-apps.document"
100+ case "application/vnd.openxmlformats-officedocument.presentationml.presentation" :
101+ return "application/vnd.google-apps.presentation"
102+ default :
103+ return "application/vnd.google-apps.unknown"
104+ }
105+ }
0 commit comments