Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
c536b8ee
U
uni-app
项目概览
DCloud
/
uni-app
2 个月 前同步成功
通知
716
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c536b8ee
编写于
11月 30, 2020
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
docs: uniCloud hosting
上级
133531d5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
23 addition
and
5 deletion
+23
-5
docs/uniCloud/faq.md
docs/uniCloud/faq.md
+3
-0
docs/uniCloud/http.md
docs/uniCloud/http.md
+20
-5
未找到文件。
docs/uniCloud/faq.md
浏览文件 @
c536b8ee
...
...
@@ -200,3 +200,6 @@ exports.main = async function(event){
关于云存储:这里的读写次数,并不一定是针对文件的:包括:上传文件、修改Policy、修改ACL、修改CORS 等操作,都会被认为是COS写。环境初始化时也会执行很多次初始化操作,写入 policy/acl/cors 等配置信息。用户每次操作 修改安全域名、修改静态域名等,也会触发 CORS 的写入。
关于数据库:开发者通过uniCloud web控制台访问数据库也会增加少量读写次数
### 部署网站到前端网页托管报“The requested file was not found on this server.”
-
部署history模式的uni-app项目时,如果未修改前端网页托管的配置,直接访问子页面时就会遇到上面的错误。如何配置请参考
[
部署uni-app项目
](
uniCloud/hosting.md?id=host-uni-app
)
docs/uniCloud/http.md
浏览文件 @
c536b8ee
...
...
@@ -151,6 +151,21 @@ uni.request({
+
请求Body大小限制,不能超过1M。
+
响应Body大小限制,不能超过1M。
云函数接收到的post请求的请求体可能是被转成base64的,如果是这样需要进行一次转化。
以接收application/json格式的post请求为例
```
js
exports
.
main
=
function
(
event
)
{
let
body
=
event
.
body
if
(
event
.
isBase64Encoded
){
body
=
Buffer
.
from
(
body
)
}
const
param
=
JSON
.
parse
(
body
)
// param为客户端上传的数据
// ...
}
```
### 云函数的返回值
...
...
@@ -160,7 +175,7 @@ uni.request({
云函数返回字符串,那么:
```
js
module
.
exports
.
main
=
function
()
{
exports
.
main
=
function
()
{
return
'
hello gateway
'
}
```
...
...
@@ -180,7 +195,7 @@ hello gateway
返回的
`Object`
会被转换为 JSON,同时 HTTP 响应的
`content-type`
会被设置为
`application/json`
:
```
js
module
.
exports
.
main
=
function
()
{
exports
.
main
=
function
()
{
return
{
foo
:
'
bar
'
}
...
...
@@ -216,7 +231,7 @@ content-length: 13
将
`content-type`
设置为
`text/html`
,即可在
`body`
中返回 HTML,会被浏览器自动解析:
```
js
module
.
exports
.
main
=
function
()
{
exports
.
main
=
function
()
{
return
{
mpserverlessComposedResponse
:
true
,
// 使用阿里云返回集成响应是需要此字段为true
statusCode
:
200
,
...
...
@@ -243,7 +258,7 @@ content-length: 14
将
`content-type`
设置为
`application/javascript`
,即可在
`body`
中返回 JavaScript 文件:
```
js
module
.
exports
.
main
=
function
()
{
exports
.
main
=
function
()
{
return
{
mpserverlessComposedResponse
:
true
,
// 使用阿里云返回集成响应是需要此字段为true
statusCode
:
200
,
...
...
@@ -270,7 +285,7 @@ console.log("Hello!")
如果返回体是诸如图片、音视频这样的二进制文件,那么可以将
`isBase64Encoded`
设置为
`true`
,并且将二进制文件内容转为 Base64 编码的字符串,例如:
```
js
module
.
exports
.
main
=
function
()
{
exports
.
main
=
function
()
{
return
{
mpserverlessComposedResponse
:
true
,
// 使用阿里云返回集成响应是需要此字段为true
isBase64Encoded
:
true
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录