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

How to use streaming in createfile and updatefile #887

Closed
andhure opened this issue May 23, 2018 · 3 comments
Closed

How to use streaming in createfile and updatefile #887

andhure opened this issue May 23, 2018 · 3 comments

Comments

@andhure
Copy link

andhure commented May 23, 2018

Hello,

I was trying to stream and upload a file to a repo using create file. Below is the code, I was trying:

try{
        let response = await octokit.repos.createFile({
            owner: "owner",
            repo: "reponame",
            path:  "lib/test.js",
            branch:"dev",
            message: 'Commit Message',
            content: new Buffer(fs.createReadStream('test.js')).toString('base64'), 
            author: {
                "name": "test-author",
                "email": "[email protected]"
            }
        })
    }

I get the error: TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.

Is it possible to stream foe this api?

@gr2m gr2m added the question label May 23, 2018
@gr2m
Copy link
Contributor

gr2m commented May 23, 2018

Hi @andhure 👋 I don’t think that this API can be streamed because the content of the file is namespaced with the property name "content": https://developer.github.com/v3/repos/contents/#create-a-file

The only API that can be streamed is Upload a release asset because the raw content of the file can be sent in the file body. We are testing that here: https://github.com/octokit/rest.js/blob/469991db293b8ffc2af6daec0bb35665793a916d/test/unit/upload-asset-test.js#L21-L27

But that’s a good question. Maybe uploading the raw content and setting the Content-Type header accordingly would work and the only thing missing is documentation for it. You could test that by using the octokit.request method, see https://github.com/octokit/rest.js/tree/master/lib/request or maybe directly the request library that we use internally: https://github.com/bitinn/node-fetch

If it does not work it might be worth asking [email protected] about it. Reference this issue if you do and keep us posted :)

@andhure
Copy link
Author

andhure commented May 24, 2018

Thanks gr2m for the quick update. I will try this and update you if there is any progress.

@stale
Copy link

stale bot commented Jun 21, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

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