应用 - 文件管理器
读取文件
从你的应用程序中读取一个文件。
GET
/
v2
/
apps
/
{app_id}
/
files
/
content
读取文件
curl --request GET \
--url https://api.squarecloud.app/v2/apps/{app_id}/files/content \
--header 'Authorization: <authorization>'import requests
url = "https://api.squarecloud.app/v2/apps/{app_id}/files/content"
headers = {"Authorization": "<authorization>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: '<authorization>'}};
fetch('https://api.squarecloud.app/v2/apps/{app_id}/files/content', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.squarecloud.app/v2/apps/{app_id}/files/content",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.squarecloud.app/v2/apps/{app_id}/files/content"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "<authorization>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.squarecloud.app/v2/apps/{app_id}/files/content")
.header("Authorization", "<authorization>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.squarecloud.app/v2/apps/{app_id}/files/content")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = '<authorization>'
response = http.request(request)
puts response.read_body{
"status": "success",
"response": {
"type": "Buffer",
"data": [
112,
111,
120,
97,
44,
32,
116,
97,
32,
113,
117,
101,
114,
101,
110,
100,
111,
32,
99,
111,
112,
105,
97,
114,
32,
97,
116,
195,
169,
32,
111,
32,
98,
117,
102,
102,
101,
114,
63
]
}
}
读取文件会返回正在运行的应用中单个文件的原始字节,以 JSON 的
{ type: "Buffer", data: number[] } 对象形式编码,而不是以流的形式返回。它用于通过 API 检查或下载单个文件(配置、日志、小型资源),而不适用于批量传输;如需拉取应用的完整副本,请使用创建快照。
在读取之前,可以先调用列出文件查看有哪些可用文件。要把文件写回,请使用创建/修改文件,它接受相同的 Buffer 格式来处理二进制内容。
在工作区共享的应用上,调用者需要具有 Maintainer 或 Administrator 角色;没有受限文件权限的成员无法读取 .env 或 .env.production,请求会在触碰文件之前就被 PERMISSION_DENIED 拒绝。
参数
string
必填
应用程序的 ID。你可以在应用程序仪表盘的 URL 中找到它。
string
必填
你想读取的文件路径。该路径相对于应用程序的根目录。
响应
string
指示调用是否成功。成功时为
success,否则为 error。{
"status": "success",
"response": {
"type": "Buffer",
"data": [
112,
111,
120,
97,
44,
32,
116,
97,
32,
113,
117,
101,
114,
101,
110,
100,
111,
32,
99,
111,
112,
105,
97,
114,
32,
97,
116,
195,
169,
32,
111,
32,
98,
117,
102,
102,
101,
114,
63
]
}
}
常见错误
| 代码 | HTTP | 说明 |
|---|---|---|
INVALID_PATH | 400 | path 查询参数未通过校验(路径穿越、非法字符或过长)。 |
PERMISSION_DENIED | 403 | 调用者缺少读取受限文件(.env、.env.production)的工作区权限。 |
FILE_NOT_FOUND | 404 | 给定路径下不存在文件。 |
FILE_TOO_LARGE | 413 | 文件过大,无法通过文件管理器读取。 |
⌘I
读取文件
curl --request GET \
--url https://api.squarecloud.app/v2/apps/{app_id}/files/content \
--header 'Authorization: <authorization>'import requests
url = "https://api.squarecloud.app/v2/apps/{app_id}/files/content"
headers = {"Authorization": "<authorization>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: '<authorization>'}};
fetch('https://api.squarecloud.app/v2/apps/{app_id}/files/content', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.squarecloud.app/v2/apps/{app_id}/files/content",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.squarecloud.app/v2/apps/{app_id}/files/content"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "<authorization>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.squarecloud.app/v2/apps/{app_id}/files/content")
.header("Authorization", "<authorization>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.squarecloud.app/v2/apps/{app_id}/files/content")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = '<authorization>'
response = http.request(request)
puts response.read_body{
"status": "success",
"response": {
"type": "Buffer",
"data": [
112,
111,
120,
97,
44,
32,
116,
97,
32,
113,
117,
101,
114,
101,
110,
100,
111,
32,
99,
111,
112,
105,
97,
114,
32,
97,
116,
195,
169,
32,
111,
32,
98,
117,
102,
102,
101,
114,
63
]
}
}

