应用 - 文件管理器
列出文件
列出你应用程序的文件。
GET
/
v2
/
apps
/
{app_id}
/
files
列出文件
curl --request GET \
--url https://api.squarecloud.app/v2/apps/{app_id}/files \
--header 'Authorization: <authorization>'import requests
url = "https://api.squarecloud.app/v2/apps/{app_id}/files"
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', 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",
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"
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")
.header("Authorization", "<authorization>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.squarecloud.app/v2/apps/{app_id}/files")
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": "file",
"name": ".env",
"size": 86,
"lastModified": 1676168978000
},
{
"type": "file",
"name": ".gitignore",
"size": 8,
"lastModified": 1675125328000
},
{
"type": "file",
"name": "index.js",
"size": 614,
"lastModified": 1676168350000
},
{
"type": "file",
"name": "squarecloud.app",
"size": 65,
"lastModified": 1676169188000
},
{
"type": "directory",
"name": "src",
"lastModified": 1676155738000
}
]
}
列出文件会返回应用内指定路径下的文件和目录,每个条目携带其类型、大小和最后修改时间。可用它在读取、写入或删除特定文件之前,从控制台或脚本中浏览应用的存储内容。
该列表反映的是请求时刻应用在其集群节点上的存储状态,不做缓存。可与读取文件搭配使用来获取文件内容,或与创建/修改文件搭配使用来写入文件。省略
path 会列出应用根目录。
在工作区共享的应用上,调用者需要具有 Maintainer 或 Administrator 角色;没有受限文件权限的成员永远不会在结果中看到 .env 或 .env.production,这些条目会从响应中被过滤掉,而不是报错。
参数
string
必填
应用程序的 ID。你可以在应用程序仪表盘的 URL 中找到它。
string
必填
你想列出其文件的目录路径。默认为根目录。
响应
string
指示调用是否成功。成功时为
success,否则为 error。array
{
"status": "success",
"response": [
{
"type": "file",
"name": ".env",
"size": 86,
"lastModified": 1676168978000
},
{
"type": "file",
"name": ".gitignore",
"size": 8,
"lastModified": 1675125328000
},
{
"type": "file",
"name": "index.js",
"size": 614,
"lastModified": 1676168350000
},
{
"type": "file",
"name": "squarecloud.app",
"size": 65,
"lastModified": 1676169188000
},
{
"type": "directory",
"name": "src",
"lastModified": 1676155738000
}
]
}
常见错误
| 代码 | HTTP | 说明 |
|---|---|---|
INVALID_PATH | 400 | path 查询参数未通过校验,或集群无法读取该目录。 |
BLOCKED_PATH | 403 | 所请求的路径位于平台的阻止路径列表中。 |
⌘I
列出文件
curl --request GET \
--url https://api.squarecloud.app/v2/apps/{app_id}/files \
--header 'Authorization: <authorization>'import requests
url = "https://api.squarecloud.app/v2/apps/{app_id}/files"
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', 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",
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"
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")
.header("Authorization", "<authorization>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.squarecloud.app/v2/apps/{app_id}/files")
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": "file",
"name": ".env",
"size": 86,
"lastModified": 1676168978000
},
{
"type": "file",
"name": ".gitignore",
"size": 8,
"lastModified": 1675125328000
},
{
"type": "file",
"name": "index.js",
"size": 614,
"lastModified": 1676168350000
},
{
"type": "file",
"name": "squarecloud.app",
"size": 65,
"lastModified": 1676169188000
},
{
"type": "directory",
"name": "src",
"lastModified": 1676155738000
}
]
}

