从远程 URL 上传文件
curl --request POST \
--url https://files-api.sinancode.com/api/upload/url \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"url": "https://example.com/image.png"
}
'import requests
url = "https://files-api.sinancode.com/api/upload/url"
payload = { "url": "https://example.com/image.png" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({url: 'https://example.com/image.png'})
};
fetch('https://files-api.sinancode.com/api/upload/url', 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://files-api.sinancode.com/api/upload/url",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'url' => 'https://example.com/image.png'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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://files-api.sinancode.com/api/upload/url"
payload := strings.NewReader("{\n \"url\": \"https://example.com/image.png\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.post("https://files-api.sinancode.com/api/upload/url")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"url\": \"https://example.com/image.png\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://files-api.sinancode.com/api/upload/url")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"url\": \"https://example.com/image.png\"\n}"
response = http.request(request)
puts response.read_body{
"url": "https://upload-tmp.sinancode.com/uploads/user123/abc123def456.png",
"cn_url": "https://beijing-user-upload-tmp.tos-cn-beijing.volces.com/uploads/user123/abc123def456.png",
"key": "uploads/user123/abc123def456.png",
"md5": "d41d8cd98f00b204e9800998ecf8427e",
"size": 12345,
"content_type": "image/png",
"expires_at": "2024-01-17T00:00:00.000Z"
}{
"message": "Missing required field: data",
"error_code": "UPLOAD.INVALID_FILE"
}{
"message": "Missing authorization token",
"error_code": "AUTH.MISSING_TOKEN"
}{
"message": "File size exceeds maximum limit of 50MB",
"error_code": "UPLOAD.FILE_TOO_LARGE"
}{
"message": "Internal server error",
"error_code": "INTERNAL_ERROR"
}文件上传
文件上传(URL)
从远程 URL 下载文件并上传到存储。
POST
/
api
/
upload
/
url
从远程 URL 上传文件
curl --request POST \
--url https://files-api.sinancode.com/api/upload/url \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"url": "https://example.com/image.png"
}
'import requests
url = "https://files-api.sinancode.com/api/upload/url"
payload = { "url": "https://example.com/image.png" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({url: 'https://example.com/image.png'})
};
fetch('https://files-api.sinancode.com/api/upload/url', 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://files-api.sinancode.com/api/upload/url",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'url' => 'https://example.com/image.png'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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://files-api.sinancode.com/api/upload/url"
payload := strings.NewReader("{\n \"url\": \"https://example.com/image.png\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.post("https://files-api.sinancode.com/api/upload/url")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"url\": \"https://example.com/image.png\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://files-api.sinancode.com/api/upload/url")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"url\": \"https://example.com/image.png\"\n}"
response = http.request(request)
puts response.read_body{
"url": "https://upload-tmp.sinancode.com/uploads/user123/abc123def456.png",
"cn_url": "https://beijing-user-upload-tmp.tos-cn-beijing.volces.com/uploads/user123/abc123def456.png",
"key": "uploads/user123/abc123def456.png",
"md5": "d41d8cd98f00b204e9800998ecf8427e",
"size": 12345,
"content_type": "image/png",
"expires_at": "2024-01-17T00:00:00.000Z"
}{
"message": "Missing required field: data",
"error_code": "UPLOAD.INVALID_FILE"
}{
"message": "Missing authorization token",
"error_code": "AUTH.MISSING_TOKEN"
}{
"message": "File size exceeds maximum limit of 50MB",
"error_code": "UPLOAD.FILE_TOO_LARGE"
}{
"message": "Internal server error",
"error_code": "INTERNAL_ERROR"
}从远程 URL 下载文件并上传到云存储。
接口特点:
- 远程下载 - 从任意公开 URL 下载文件并转存
- 自定义文件名 - 可选指定保存的文件名
- 大文件支持 - 最大支持 50MB 文件上传
- 双线路 - 返回全球和中国两个访问 URL
授权
从 api.sinancode.com 获取的授权令牌
请求体
application/json
响应
文件上传成功
已上传文件的公开访问 URL(全球)
示例:
"https://upload-tmp.sinancode.com/uploads/user123/abc123def456.png"
已上传文件的公开访问 URL(中国)
示例:
"https://beijing-user-upload-tmp.tos-cn-beijing.volces.com/uploads/user123/abc123def456.png"
已上传文件的存储键
示例:
"uploads/user123/abc123def456.png"
文件内容的哈希值(SHA-256 截断)
示例:
"d41d8cd98f00b204e9800998ecf8427e"
文件大小(字节)
示例:
12345
文件的 MIME 类型
示例:
"image/png"
文件过期时间(ISO 8601 格式)
示例:
"2024-01-17T00:00:00.000Z"
⌘I