您好,欢迎访问一九零五行业门户网

微信小程序网络API 上传、下载详细说明

这篇文章主要介绍了微信小程序网络api 上传、下载详细说明的相关资料,需要的朋友可以参考下
wx.uploadfile(object)
将本地资源上传到开发者服务器。如页面通过 wx.chooseimage 等接口获取到一个本地资源的临时文件路径后,可通过此接口将本地资源上传到指定服务器。客户端发起一个https post请求,其中 content-type 为 multipart/form-data 。
object参数说明:
参数类型必填说明
url string 是 开发者服务器url
filepath string 是 要上传文件资源的路径
name string 是 文件对应的key , 开发者在服务器端通过这个key可以获取到文件二进制内容
header object 否 http 请求 header
formdata object 否 http 请求中其他额外的form data
success function 否 接口调用成功的回调函数
fail function 否 接口调用失败的回调函数
complete function 否 接口调用结束的回调函数(调用成功、失败都会执行)
示例代码:
wx.chooseimage({ success:function(res){ var tempfilepaths = res.tempfilepaths; wx.uploadfile({ url: 'http://example.com/upload', filepath: tempfilepaths[0], name:"file", formdata:{ "user":"test" } }) } })
wx.downloadfile(object)
下载文件资源到本地。客户端直接发起一个http get请求,把下载到的资源根据 type 进行处理,并返回文件的本地临时路径。
object参数说明:
参数类型必填必填
url string 是 下载资源的 url
type string 否 下载资源的类型,用于客户端识别处理,有效值:image/audio/video
header object 否 http 请求 header
success function 否 下载成功后以 tempfilepath 的形式传给页面,res={tempfilepath:"文件的临时路径"}
fail function 否 接口调用失败的回调函数
complete function 否 接口调用结束的回调函数(调用成功、失败都会执行)
示例代码:
wx.downloadfile({ url: 'http://example.com/audio/123', type: 'audio', success:function(res){ wx.playvoice({ filepath: res.tempfilepath }) } })
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
以上就是微信小程序网络api 上传、下载详细说明的详细内容。
其它类似信息

推荐信息