Comments (6)
你用的是 http.request?
http.request({
// baseURL: '',
method: 'POST', // 请求方法必须大写 [GET|POST|PUT|DELETE|CONNECT|HEAD|OPTIONS|TRACE]
request 不支持 Upload 方法。
上传文件使用http.upload
from luch-request.
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}})
然后像正常调用接口调用,下方红框内是可以正常使用的(uni.uploadFile),但是接口调用报错;上方content-type不需要理会,设置与否都会报这个错
两个问题需要请教:
1、如果是参数传的方式不对,应该如何传,我传的是小程序返回的图片临时路径;
2、这个method总是显示upload方式,但是http请求不支持这种方式的;
有没有示例可以参考一下啊?问了很多人,基本没人用这种方式,只能请教作者大佬了,还请不吝赐教!!
from luch-request.
uni.chooseImage({
sus: (res) = > {
let tempFilePaths = res.tempFilePaths[0]
http.upload('upload', {
filePath: tempFilePaths,
name: 'file'
})
}
})
所有的 请求方式肯定只支持http 的那几种方式。没有upload,方法。
from luch-request.
为什么 插件的 method 显示的事 upload
因为 插件 是 uni api 的上层。也就是说,我的插件也是基于 uni 的api 去实现的。如果uni 的api 实现不了的功能,我的插件也实现不了。
因为拦截器那块还没到 底层调用,我得区分我最后要调用 uni 的哪个api。比如最后 我发现 method === uplaod 我就去调用 uni.upload 。
如果 你用 h5 去调用 http.upload 或者 uni.uplaod 你就会发现。本质上 还是 http 的post 请求
from luch-request.
哪怕是 axios 我都可以 定义 一个 method 为 luch 的请求方式。
因为你传的 method 不一定是我最后调用 xhr 时 传的请求方式。 我只要最后发现 method === luch ,我调用xhr 的请求方式时使用 post 请求。
from luch-request.
所以http.upload()这个方法只能在h5使用吗?上传图片这种业务除了使用uni.upload()这种方式,不能使用你这种http.upload()的调用接口的方式吗?不应该是判断method===upload,然后就把method改成post吗,对不起大佬 我还是搞不懂你这个到底是能不能用来上传图片,如何使用这个上传图片....
from luch-request.
Related Issues (20)
- 我有一个接口对接了chatgpt,数据是流式返回的,如何能流式的取数据? HOT 4
- 没有 PATCH请求方式吗 ? HOT 2
- 支持 async、await 嘛 HOT 1
- node版本限制应是大于等于16,而非16吧,否则node18会无法安装 HOT 4
- 是不是响应拦截器不支持nvue页面啊,今天试了一天,发现在nvue页面拦截器不生效 HOT 6
- 如何去掉Get请求头的content-type属性 HOT 1
- 请问有没有遇到过这个问题,new这个类,直接使用request.delete会说is not a function?如果是request.get或者post或者put都正常,唯独delete有问题 HOT 2
- validateStatus设置无效 HOT 3
- 麻烦看一下custom无法定义类型这个问题 HOT 1
- 上传多个文件时files参数怎么传?服务器端收到的ContentType为何是text/html HOT 2
- 关于vue.config.js中transpileDependencies配置问题 HOT 3
- 可以考虑封装一个useRequest uniapp版本的
- get请求可以禁止302重定向吗
- http.upload('api/upload/img', ;这个怎么用?method是upload? HOT 2
- ios17.2.1 调用接口一直在加载中 HOT 2
- forcedJSONParsing 没有类型提示呀
- 微信小程序调用没有反应,基础库3.3.3
- 【BUG】设置请求超时 timeout 没有效果 HOT 5
- 怎么进行流式内容的获取? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from luch-request.