11import googleDrive from "../../google_drive.app.mjs" ;
22import path from "path" ;
33import {
4- getFileStream ,
54 omitEmptyStringValues ,
65 parseObjectEntries ,
76} from "../../common/utils.mjs" ;
87import { GOOGLE_DRIVE_UPLOAD_TYPE_MULTIPART } from "../../common/constants.mjs" ;
98import {
10- additionalProps , updateType ,
11- } from "../../common/filePathOrUrl.mjs " ;
9+ getFileStream , ConfigurationError ,
10+ } from "@pipedream/platform " ;
1211
1312export default {
1413 key : "google_drive-upload-file" ,
1514 name : "Upload File" ,
1615 description : "Upload a file to Google Drive. [See the documentation](https://developers.google.com/drive/api/v3/manage-uploads) for more information" ,
1716 version : "1.1.0" ,
1817 type : "action" ,
19- additionalProps,
2018 props : {
2119 googleDrive,
22- updateType,
2320 drive : {
2421 propDefinition : [
2522 googleDrive ,
@@ -39,21 +36,10 @@ export default {
3936 "The folder you want to upload the file to. If not specified, the file will be placed directly in the drive's top-level folder." ,
4037 optional : true ,
4138 } ,
42- fileUrl : {
43- propDefinition : [
44- googleDrive ,
45- "fileUrl" ,
46- ] ,
47- optional : true ,
48- hidden : true ,
49- } ,
50- filePath : {
51- propDefinition : [
52- googleDrive ,
53- "filePath" ,
54- ] ,
55- optional : true ,
56- hidden : true ,
39+ file : {
40+ type : "string" ,
41+ label : "File" ,
42+ description : "Provide either a file URL or a path to a file in the /tmp directory (for example, /tmp/myFlie.pdf)." ,
5743 } ,
5844 name : {
5945 propDefinition : [
@@ -98,26 +84,24 @@ export default {
9884 async run ( { $ } ) {
9985 const {
10086 parentId,
101- fileUrl,
102- filePath,
10387 name,
10488 mimeType,
10589 } = this ;
10690 let { uploadType } = this ;
10791 const driveId = this . googleDrive . getDriveId ( this . drive ) ;
10892
109- const filename = name || path . basename ( fileUrl || filePath ) ;
93+ const filename = name || path . basename ( this . file ) ;
11094
111- const file = await getFileStream ( {
112- $,
113- fileUrl,
114- filePath : filePath ?. startsWith ( "/tmp/" )
115- ? filePath
116- : `/tmp/${ filePath } ` ,
117- } ) ;
95+ const file = await getFileStream ( this . file ) ;
11896 console . log ( `Upload type: ${ uploadType } .` ) ;
11997
120- const metadata = parseObjectEntries ( this . metadata ) ;
98+ const metadata = this . metadata
99+ ? parseObjectEntries ( this . metadata )
100+ : undefined ;
101+
102+ if ( metadata ?. mimeType && ! mimeType ) {
103+ throw new ConfigurationError ( `Please include the file's original MIME type in the \`Mime Type\` prop. File will be converted to \`${ metadata . mimeType } \`.` ) ;
104+ }
121105
122106 let result = null ;
123107 if ( this . fileId ) {
0 commit comments