Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multipart upload file to google drive API #257

Open
kokosky93 opened this issue Dec 7, 2019 · 1 comment
Open

Multipart upload file to google drive API #257

kokosky93 opened this issue Dec 7, 2019 · 1 comment

Comments

@kokosky93
Copy link

kokosky93 commented Dec 7, 2019

I am meeting with dificulties while using multipartUpload method. I need to send json file to the Google Drive API. I have to use multipart to set metadata to a file like name. Without multipart request file will be with untitled name. I don't know how to set boundaries according to Google Drive API documentations. Anyone can help?

This is my code:

    let documents = knownFolders.documents();
    let folder = documents.getFolder("testFolder");
    let file = folder.getFile(("test") + ".json");

    var xxx = { "thing": "cat", "age": "19" };
    var jsonFile = JSON.stringify(xxx);

    file.writeText(jsonFile)
        .then(result => {

            var bghttp = require("nativescript-background-http");
            var session = bghttp.session("file-upload");

            var request = {
                url: "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart",
                method: "POST",
                headers: {
                    "Content-Type": "multipart/related",
                    "Authorization": `Bearer ${this.token.accessToken}`,
                },
                utf8: true
            };

            var params = [
                { name: "test", value: "I need to send metadata to the file I don't know how" },
                { name: "test", filename: file.path, mimeType: "application/json" }
            ];
            var task = session.multipartUpload(params, request);

I have tried a lot but nothing worked out.

Google API
https://developers.google.com/drive/api/v3/manage-uploads

@lini
Copy link
Contributor

lini commented Dec 16, 2019

Can you try saving your metadata as a json file and uploading it like you do the other file? This way you will be able to specify the content type of the metadata as application/json; charset=UTF-8 as the GDrive API expects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants