Giter Site home page Giter Site logo

Comments (6)

lei-mu avatar lei-mu commented on May 27, 2024

使用http.upload

你用的是 http.request?

http.request({
    // baseURL: '',
    method: 'POST', // 请求方法必须大写 [GET|POST|PUT|DELETE|CONNECT|HEAD|OPTIONS|TRACE] 

request 不支持 Upload 方法。

上传文件使用http.upload

from luch-request.

yangxun521 avatar yangxun521 commented on May 27, 2024

https://www.quanzhan.co/luch-request/guide/3.x/#upload
非常抱歉 我是滚动页面到#upload这里,但是没注意url是#request,让作者产生歧义了。

export const upl = file => uni.$uv.http.upload('resource/oss/upload', {filePath: file, header: { 'Content-Type': 'multipart/form-data' }, custom: {auth: true}})
093e25b9e0e3cee95a348d623084e7d

然后像正常调用接口调用,下方红框内是可以正常使用的(uni.uploadFile),但是接口调用报错;上方content-type不需要理会,设置与否都会报这个错
bf7c5b1760087b7a85c55e0fb83b5cd

7a733e3bafb46a58ade21ac752745ff
两个问题需要请教:
1、如果是参数传的方式不对,应该如何传,我传的是小程序返回的图片临时路径;
2、这个method总是显示upload方式,但是http请求不支持这种方式的;
有没有示例可以参考一下啊?问了很多人,基本没人用这种方式,只能请教作者大佬了,还请不吝赐教!!

from luch-request.

lei-mu avatar lei-mu commented on May 27, 2024
uni.chooseImage({
    sus: (res) = > {
        let tempFilePaths = res.tempFilePaths[0]
        http.upload('upload', {
            filePath: tempFilePaths,
            name: 'file'
        })
    }
})

所有的 请求方式肯定只支持http 的那几种方式。没有upload,方法。

from luch-request.

lei-mu avatar lei-mu commented on May 27, 2024

为什么 插件的 method 显示的事 upload

因为 插件 是 uni api 的上层。也就是说,我的插件也是基于 uni 的api 去实现的。如果uni 的api 实现不了的功能,我的插件也实现不了。
因为拦截器那块还没到 底层调用,我得区分我最后要调用 uni 的哪个api。比如最后 我发现 method === uplaod 我就去调用 uni.upload 。
如果 你用 h5 去调用 http.upload 或者 uni.uplaod 你就会发现。本质上 还是 http 的post 请求

from luch-request.

lei-mu avatar lei-mu commented on May 27, 2024

哪怕是 axios 我都可以 定义 一个 method 为 luch 的请求方式。

因为你传的 method 不一定是我最后调用 xhr 时 传的请求方式。 我只要最后发现 method === luch ,我调用xhr 的请求方式时使用 post 请求。

from luch-request.

yangxun521 avatar yangxun521 commented on May 27, 2024

所以http.upload()这个方法只能在h5使用吗?上传图片这种业务除了使用uni.upload()这种方式,不能使用你这种http.upload()的调用接口的方式吗?不应该是判断method===upload,然后就把method改成post吗,对不起大佬 我还是搞不懂你这个到底是能不能用来上传图片,如何使用这个上传图片....

from luch-request.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.