Question

I am using Quickstart: Run a Drive app in JavaScript tutorial to upload documents to google drive. I am successfully able to run the HTML file and upload the document.

For example I uploaded a test.docx file and the JSON response is at the end of the post

The question is, the alternate link opens up the doc in view only(pdf like) mode. For this example here is the link https://docs.google.com/a/easytha.com/file/d/0B7x-2AmDcIyRN3hPVVRWSUhQaWs/edit

but how do I build a URL so that it opens up in edit mode like this https://docs.google.com/a/easytha.com/document/d/1rH79lwfX4bZ4R5EEhSaTy52dfdKiezNOaaR-6ORBcoI/edit

And both of these are the same documents.

alternateLink
    "https://docs.google.com...hQaWs/edit?usp=drivesdk"

appDataContents
    false

copyable
    true

createdDate
    "2014-01-31T10:01:31.092Z"

downloadUrl
    "https://doc-00-10-docs....4259&e=download&gd=true"

editable
    true

etag
    ""GJcqFgACxaboeo6aKKeP6-mh0PE/MTM5MTE2MjQ5MDg1NQ""

fileExtension
    "docx"

fileSize
    "12497"

iconLink
    "https://ssl.gstatic.com...s/icon_10_word_list.png"

id
    "0B7x-2AmDcIyRN3hPVVRWSUhQaWs"

kind
    "drive#file"

labels
    Object { starred=false, hidden=false, trashed=false, more...}

lastModifyingUser
    Object { kind="drive#user", displayName="sapan parikh", isAuthenticatedUser=true, more...}

lastModifyingUserName
    "sapan parikh"

lastViewedByMeDate
    "2014-01-31T10:01:30.855Z"

md5Checksum
    "0acf21000754601319600c5182d794d4"

mimeType
    "application/vnd.openxml...rdprocessingml.document"

modifiedByMeDate
    "2014-01-31T10:01:30.855Z"

modifiedDate
    "2014-01-31T10:01:30.855Z"

originalFilename
    "test.docx"

ownerNames
    ["sapan parikh"]

owners
    [Object { kind="drive#user", displayName="sapan parikh", isAuthenticatedUser=true, more...}]

parents
    [Object { kind="drive#parentReference", id="0ALx-2AmDcIyRUk9PVA", selfLink="https://content.googlea...nts/0ALx-2AmDcIyRUk9PVA", more...}]

quotaBytesUsed
    "12497"

selfLink
    "https://content.googlea...2AmDcIyRN3hPVVRWSUhQaWs"

shared
    false

title
    "test.docx"

userPermission
    Object { kind="drive#permission", etag=""GJcqFgACxaboeo6aKKeP6-...XMO0VKCtlQA-JDZdgem3VQ"", id="me", more...}

webContentLink
    "https://docs.google.com...SUhQaWs&export=download"

writersCanShare
    true
Was it helpful?

Solution

I ran in to this too. The problem is Google drive can only edit Google drive docs. So when you upload a docx file it creates a new Google drive doc and redirects you to this when you want to edit this. This means it's a different document. I'm not sure about the JavaScript API but in C# there was an option to convert the document while uploading.

OTHER TIPS

Maybe this is a bit late, but might help someone ...

This is how you can do it in nodejs using the googleapis module ...

//imports
var google = require('googleapis');
var key = require(path.join(__dirname, 'myGoogleAppJWTtoken.json'));

//method
var jwtClient = new google.auth.JWT(key.client_email, null, key.private_key, ['https://www.googleapis.com/auth/drive'], null);
var drive = google.drive('v3');

drive.files.create({
            auth: jwtClient, // jwt auth variable
            resource: { 
                name: 'DemoDoc', // saved name & google docs mimetype below
                mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' 
            },
            media: {
                mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
                body: fs.createReadStream('DemoDoc.docx') // my document
            }
        }, function(err,res){
            if(err){
                throw err;
            }else{
                console.log("SuccessFull...");
            }
        });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top