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

uploadParams无效 #44

Open
Allen820 opened this issue Oct 25, 2023 · 1 comment
Open

uploadParams无效 #44

Allen820 opened this issue Oct 25, 2023 · 1 comment

Comments

@Allen820
Copy link

Allen820 commented Oct 25, 2023

upload (file, success) {
let url = this.config.uploadUrl
let xhr = new XMLHttpRequest()
let form = new FormData()
let self = this
if (!!config.uploadParams) {
Object.keys(this.config.uploadParams).map((i) => {
form.append(i, this.config.uploadParams[i]);
});
}
form.append(this.config.uploadName, file)
xhr.open('POST', url, true)
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
const json = JSON.parse(xhr.responseText)
const imgUrl = self.config.uploadCallback(json)
success(imgUrl)
} else {
if (self.config.uploadFailed) {
self.config.uploadFailed(xhr.responseText)
}
// 测试网站, 模拟上传
if (location.href.indexOf('ericjj.com/smeditor.github.io') > 0) {
const imgUrl = self.config.uploadCallback('')
success(imgUrl)
}
}
}
}
xhr.send(form)
}

@Allen820
Copy link
Author

Allen820 commented Oct 26, 2023

upload (file, success) {
  let url = this.config.uploadUrl
  let xhr = new XMLHttpRequest()
  let form = new FormData()
  let self = this
  if (!!this.config.uploadParams) {
    Object.keys(this.config.uploadParams).map((i) => {
  	  form.append(i, this.config.uploadParams[i]);
    });
  }
  form.append(this.config.uploadName, file)
  xhr.open('POST', url, true)
  xhr.onreadystatechange = function () {
    if (xhr.readyState === 4) {
      if (xhr.status === 200) {
        const json = JSON.parse(xhr.responseText)
        const imgUrl = self.config.uploadCallback(json)
        success(imgUrl)
      } else {
        if (self.config.uploadFailed) {
          self.config.uploadFailed(xhr.responseText)
        }
        // 测试网站, 模拟上传
        if (location.href.indexOf('ericjj.com/smeditor.github.io') > 0) {
          const imgUrl = self.config.uploadCallback('')
          success(imgUrl)
        }
      }
    }
  }
  xhr.send(form)
}
/

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

1 participant