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
Upload a zip file as content for InputGitTreeElement #863
Comments
What's your original use case? Just uploading a file to your repo? If so, there is a upload api you can use. (but limited to upload one file at a time) |
First, I forgot to say that I am using Python3. repo.create_git_commit(commit_msg, end_tree, parents=[commit.commit]) end_tree is a list of InputGitTreeElement. Each one corresponds to a file. My problem becomes that the 'content' of InputGitTreeElement can only be of type 'str' or 'unicode'. When I load a file to memory I have type 'bytes'. What is the right way to encode those bytes to str or unicode so InputGitTreeElement can upload my file? thanks! |
You can use blob. import base64
blob = repo.create_git_blob("XXX", encoding='utf-8')
blob = repo.get_git_blob(sha=blob.sha)
tree_element = InputGitTreeElement(path='', mode='100644', type='blob', content=base64.b64decode(blob.content).decode('utf-8')) |
It wouldn't be the same problem?
|
replace |
Is not able to decode it as utf-8:
It is a zip file. Should be expected to be encoded in utf-8? |
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. |
Did you manage to solve this? I'm having the same problem. I can't find a way to upload a png file. |
I have the same problem, i cant send a simple image file. |
You Can Try This : data = base64.b64encode(open(file_name, "rb").read())
path = "{}/{}/{}".format(now.year, now.month, "tweets.zip")
blob = repo.create_git_blob(data.decode("utf-8"), "base64")
element = InputGitTreeElement(path=path, mode='100644', type='blob', sha=blob.sha)
element_list.append(element)
tree = repo.create_git_tree(element_list, base_tree)
parent = repo.get_git_commit(master_sha)
commit = repo.create_git_commit("commit_message", tree, [parent])
master_ref.edit(commit.sha)``` |
is there any possible solution to this thread?
|
This is a question:
I am trying to upload zip files to my repo by creating a tree with a bunch of InputGitTreeElement elements. Some of these InputGitTreeElement are zip files. InputGitTreeElement only accepts 'str' for content. How can I do this?
thanks!
The text was updated successfully, but these errors were encountered: