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

如果遇到上传不成功,可能是因为上传地址不是https的问题。 #44

Open
54sword opened this issue Mar 29, 2018 · 2 comments

Comments

@54sword
Copy link

54sword commented Mar 29, 2018

使用过程遇到了上传无反应的问题,然后发现源代码上传地址都是http的,修改成https后正常了。
打开你项目中的 node_modules/react-native-qiniu/code/conf.js 文件,都加上https。

let UP_HOST = 'https://up.qbox.me/';
let RS_HOST = 'https://rs.qbox.me';
let RSF_HOST = 'https://rsf.qbox.me';
let API_HOST = 'https://api.qiniu.com';

然后七牛存储区域不同,上传的地址也可能也会不同,大家注意了,一般返回错误中会有提示,看错误修改地址就可以了。

储存区域地址
https://developer.qiniu.com/kodo/manual/1671/region-endpoint

@lsslu
Copy link

lsslu commented Apr 1, 2018

感谢!还真遇到了这个问题。。。

@youngjuning
Copy link

我fork了一份,支持动态传递 region ,在上传成功后返回key: https://github.com/sishuguojixuefu/react-native-sdk
引入方式:

"dependencies": {
    "react-native-qiniu": "git+https://[email protected]/sishuguojixuefu/react-native-sdk.git"
  }

使用方式:

/**
 * 直传文件
 * @param {string} filePath
 */
const uploadToQiniu = async (filePath, baseUrl) => {
  console.log('filePath:', /^file:\/\/(.*)$/.exec(filePath)[1])
  const uploadToken = await getUploadToken(baseUrl)
  // uploadFile(uri, token, formInput, onprogress)
  const key = await qiniu.Rpc.uploadFile(
    /^file:\/\/(.*)$/.exec(filePath)[1], //图片地址
    uploadToken, // 上传令牌
    {
      key: uuid.v4(), // 表示你资源上传到七牛云之后保存的文件名
      type: 'application/octet-stream', // 表示uri所代表的类型,此处为二进制流,上传文件一般都是二进制
      name: undefined, // 未知,随便什么
      region: 'https://up-z1.qiniup.com',
    },
    resp => {
      console.log(resp)
    }
  )
  return `http://qiniu.sishuxuefu.com/${res.key}`
}

const getUploadToken = async baseUrl => {
  const { data } = await axios.get(`${baseUrl}api/qiniu/uploadtoken`)
  return data
}

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

3 participants