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 upload files to repository files list? #1451

Open
p3tr0v opened this issue Apr 17, 2022 · 4 comments
Open

How to upload files to repository files list? #1451

p3tr0v opened this issue Apr 17, 2022 · 4 comments
Labels

Comments

@p3tr0v
Copy link

p3tr0v commented Apr 17, 2022

Hi guys, I'm trying to upload a file then see it in repository file list.
I saw issue number #1272 , it solved part of the problem.
The method client.Projects.UploadFile() upload the file, but the file isn't listed in repository file listed. To be true, I didn't find the uploaded file in anywhere in my gitlab, there is only the "Readme.md" file!
This is my code

		bodyFileimage, _ := ioutil.ReadFile(string(bytes.TrimSpace([]byte("save.png"))))
		reader := bytes.NewReader(bodyFileimage)
	
		fi, _, err := client.Projects.UploadFile(projectID, reader, "save.png")
		if err != nil {
			fmt.Println(err)
		}
		fmt.Println(fi.URL)

The output of fmt.Println is
/uploads/b0dc0d16f4476470baae543eb97c3449/save.png

If I copy and paste this URL in my project I see the image, but not in repository list.

I'm using GitLab 14.9.3

Thanks very much

@Nihilism0
Copy link

you can try GitlabClient.RepositoryFiles.CreateFile(projectId, targetPath+"/"+file.Name(), opts)
I also encountered the same problem as you, but I solved it using the above function. So far, I don't know what uploadfiles are used for

@svanharmelen
Copy link
Member

Is this still an issue, or can this one be closed?

@Nihilism0
Copy link

image

you can try this

@Nihilism0
Copy link

https://docs.gitlab.com/ee/api/commits.html#create-a-commit-with-multiple-files-and-actions

This is the official API, and you can also find some answers from it

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

No branches or pull requests

3 participants