flow_be/doc/file.md
2022-11-22 15:54:40 +08:00

53 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 1. 文件上传
1. MethodPOST
2. HOST: http://file.domain.com
3. URIfile/upload_one
| 字段 | 说明 | 类型 |
| ----- | ---- | ---- |
| image | 文件 | file |
3. ResponseJSON
| 字段 | 类型 | 说明 |
| -------| ------ | -------- |
| code | Number | 错误代码 |
| msg | String | 错误信息 |
| img | String | 图片远程地址 |
| qr | String | 二维码地址 |
4. errcode 定义
| 字段 | 说明 |
| ---- | -------------- |
| 0 | 无错误 |
| 11 | 服务端错误 |
| 100 | 一般性错误 |
| 50x | 服务错误 |
| 30x | 无权限访问该接口 |
5. 示例代码
```bash
curl --location --request POST 'http://file.domain.com/file/upload_one' \
--form 'image=@/data/Pictures/5c14a679db141e0c4ebc5379.png'
```
```java
// use OKHttp
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("image","5c14a679db141e0c4ebc5379.png",
RequestBody.create(MediaType.parse("application/octet-stream"),
new File("/data/images/5c14a679db141e0c4ebc5379.png")))
.build();
Request request = new Request.Builder()
.url("http://file.domain.com/file/upload_one")
.method("POST", body)
.build();
Response response = client.newCall(request).execute();
```