リモート 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 から直接アップロード - ファイルをダウンロードせずに URL を指定するだけ
- 自動フェッチ - システムが 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