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

[BUG]: upload mutil files will get error #378

Open
1 task done
CooperHash opened this issue Nov 4, 2023 · 4 comments
Open
1 task done

[BUG]: upload mutil files will get error #378

CooperHash opened this issue Nov 4, 2023 · 4 comments
Labels
Status: Up for grabs Issues that are ready to be worked on by anyone Type: Support Any questions, information, or general needs around the SDK or GitHub APIs

Comments

@CooperHash
Copy link

What happened?

like i make a for loop to upload image to my repo, sometimes will get upload fail

RequestError [HttpError]: is at 91929f0428b56ddc3f12c6b6e33352d59xxxxxxx but expected 4a9b48ee99c3533e3bf578829b1e23bxxxxxxxx

that error means: in this for loop i already upload a.jpg then after i upload a.jpg again, because the sha of the same file is the same

but i promise in the for loop all the file are different, i just don't know why, and i even make a timeout also don't work, sometimes 3 image i can upload 2, sometimes all work, this error don't repeat every time...

Versions

Octokit v8.1.4 Node v18.17.1

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@CooperHash CooperHash added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Nov 4, 2023
Copy link
Contributor

github-actions bot commented Nov 4, 2023

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@kfcampbell kfcampbell added Type: Support Any questions, information, or general needs around the SDK or GitHub APIs Status: Up for grabs Issues that are ready to be worked on by anyone and removed Status: Triage This is being looked at and prioritized labels Nov 7, 2023
@wolfy1339
Copy link
Member

Can you share some code that demonstrates the issue you are facing?

@CooperHash
Copy link
Author

async function uploadGithub(filePath) {
  const base64Image = fs.readFileSync(filePath, 'base64');
  console.log('sha', sha);
  const response = await octokit.request('PUT /repos/${repoOwner}/${repoName}/contents/weibo/test/filePath, {
    owner: repoOwner,
    repo: repoName,
    path: path,
    message: update,
    committer: {
      name: 'xxx',
      email: 'xxx'
    },
    content: base64Image,
    headers: {
      'X-GitHub-Api-Version': '2022-11-28'
    }
  })
  return response.data.content.download_url;
}

const jpgFiles = fs.readdirSync('./').filter((file) => file.endsWith('.jpg'));

async function uploadAllFiles() {
  for (const file of jpgFiles) {
    const filePath = path.join('./', file)
    const content = fs.readFileSync(filePath,'base64');
    console.log('filepath',file);
    try {
      await uploadFile(filePath, content);
    } catch (error) {
      console.error(`Error uploading file ${filePath}: ${error.message}`);
    }
  }
}

uploadAllFiles();

make a for loop upload all the jpg file in root dir, sometimes 01 img is failed, then i delete all upload files in repo and repeat again sometimes 02 img is failed get error like issue i mention, so i can't locate the problem, and i make sure every img is different and every img filename is different and github repo don't have same file

@CooperHash
Copy link
Author

const octokit = require('../utils/octokit')
const {repoName, repoOwner} = require('../const/github')
const get_github =  async (path) => {
  const response = await octokit.request(`GET /repos/${repoOwner}/${repoName}/contents/weibo/${path}/`, {
    owner: `${repoOwner}`,
    repo: `${repoName}`,
  })
  return response.data
}


const delete_github = async (path) => {
  const filepath = path
  const list = await get_github(filepath)
  console.log(list.slice(0,1));
  for(const item of list) {
    if(String(item.name).endsWith('.jpg')) {
      console.log('is jpg photo',item.path);
      octokit.request(`DELETE /repos/${repoOwner}/${repoName}/contents/${item.path}`, {
        owner: `${repoOwner}`,
        repo: `${repoName}`,
        sha: item.sha,
        path: item.path,
        message: `${item.name}`,
      })
    }
  }
}

delete_github('zilin')

i don't know whether every delete request will change other file's sha, if so that can explain why
image

@wolfy1339 wolfy1339 removed the Type: Bug Something isn't working as documented label Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Up for grabs Issues that are ready to be worked on by anyone Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects
Status: 🔥 Backlog
Development

No branches or pull requests

3 participants