应用 - 文件管理器
移动文件
在你的应用程序中移动一个文件。
PATCH
/
v2
/
apps
/
{app_id}
/
files
移动文件
curl --request PATCH \
--url https://api.squarecloud.app/v2/apps/{app_id}/files \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"path": "<string>",
"to": "<string>"
}
'import requests
url = "https://api.squarecloud.app/v2/apps/{app_id}/files"
payload = {
"path": "<string>",
"to": "<string>"
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({path: '<string>', to: '<string>'})
};
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 => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'path' => '<string>',
'to' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.squarecloud.app/v2/apps/{app_id}/files"
payload := strings.NewReader("{\n \"path\": \"<string>\",\n \"to\": \"<string>\"\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.patch("https://api.squarecloud.app/v2/apps/{app_id}/files")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"path\": \"<string>\",\n \"to\": \"<string>\"\n}")
.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::Patch.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"path\": \"<string>\",\n \"to\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"status": "success"
}
移动文件会将应用存储中的单个文件从
path 重命名或移动到 to,而无需下载并重新上传其内容。可用它重新组织目录结构,或就地重命名配置文件。
path 和 to 都必须通过路径校验且必须互不相同,二者传入相同的值会被 INVALID_PATH 拒绝。此操作只会移动正在运行的应用存储中的文件,不会重启进程,因此正在运行、仍读取旧路径的进程不会立即感知这一变化,直到它重新加载或应用被重启。要删除文件而不是移动它,请参阅删除文件。
在工作区共享的应用上,调用者需要具有 Maintainer 或 Administrator 角色。受限文件检查同时适用于源文件名和目标文件名,因此没有该权限的成员无法通过将允许的文件重命名为 .env 等受保护名称来植入或覆盖它。
参数
string
必填
应用程序的 ID。你可以在应用程序仪表盘的 URL 中找到它。
string
必填
要移动的文件路径。
string
必填
文件要移动到的目标路径。
响应
string
指示调用是否成功。成功时为
success,否则为 error。{
"status": "success"
}
常见错误
| 代码 | HTTP | 说明 |
|---|---|---|
INVALID_PATH | 400 | path 或 to 未通过校验,或 path 与 to 相同。 |
RENAME_FAILED | 400 | 集群无法重命名该文件。 |
PERMISSION_DENIED | 403 | 调用者缺少重命名受限文件的工作区权限,该检查同时针对源文件名和目标文件名。 |
⌘I
移动文件
curl --request PATCH \
--url https://api.squarecloud.app/v2/apps/{app_id}/files \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"path": "<string>",
"to": "<string>"
}
'import requests
url = "https://api.squarecloud.app/v2/apps/{app_id}/files"
payload = {
"path": "<string>",
"to": "<string>"
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({path: '<string>', to: '<string>'})
};
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 => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'path' => '<string>',
'to' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.squarecloud.app/v2/apps/{app_id}/files"
payload := strings.NewReader("{\n \"path\": \"<string>\",\n \"to\": \"<string>\"\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.patch("https://api.squarecloud.app/v2/apps/{app_id}/files")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"path\": \"<string>\",\n \"to\": \"<string>\"\n}")
.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::Patch.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"path\": \"<string>\",\n \"to\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"status": "success"
}

