Using files

Gemini API รองรับการอัปโหลดไฟล์สื่อแยกจากการป้อนพรอมต์ ซึ่งช่วยให้คุณนำสื่อไปใช้ซ้ำในคำขอและพรอมต์หลายรายการได้ ดูรายละเอียดเพิ่มเติมได้ที่คู่มือการใช้พรอมต์ด้วยสื่อ

วิธีการ: media.upload

สร้าง File

ปลายทาง

  • URI การอัปโหลดสำหรับคำขออัปโหลดสื่อ
โพสต์ https://generativelanguage.googleapis.com/upload/v1beta/files
  • URI ของข้อมูลเมตาสำหรับคำขอข้อมูลเมตาเท่านั้น
โพสต์ https://generativelanguage.googleapis.com/v1beta/files

เนื้อหาของคำขอ

เนื้อความของคำขอมีข้อมูลซึ่งมีโครงสร้างดังต่อไปนี้

ฟิลด์
file object (File)

ไม่บังคับ ข้อมูลเมตาของไฟล์ที่จะสร้าง

ตัวอย่างคำขอ

รูปภาพ

Python

from google import genai

client = genai.Client()
myfile = client.files.upload(file=media / "Cajun_instruments.jpg")
print(f"{myfile=}")

result = client.models.generate_content(
    model="gemini-2.0-flash",
    contents=[
        myfile,
        "\n\n",
        "Can you tell me about the instruments in this photo?",
    ],
)
print(f"{result.text=}")

Node.js

// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const myfile = await ai.files.upload({
  file: path.join(media, "Cajun_instruments.jpg"),
  config: { mimeType: "image/jpeg" },
});
console.log("Uploaded file:", myfile);

const result = await ai.models.generateContent({
  model: "gemini-2.0-flash",
  contents: createUserContent([
    createPartFromUri(myfile.uri, myfile.mimeType),
    "\n\n",
    "Can you tell me about the instruments in this photo?",
  ]),
});
console.log("result.text=", result.text);

Go

file, err := client.UploadFileFromPath(ctx, filepath.Join(testDataDir, "Cajun_instruments.jpg"), nil)
if err != nil {
	log.Fatal(err)
}
defer client.DeleteFile(ctx, file.Name)

model := client.GenerativeModel("gemini-1.5-flash")
resp, err := model.GenerateContent(ctx,
	genai.FileData{URI: file.URI},
	genai.Text("Can you tell me about the instruments in this photo?"))
if err != nil {
	log.Fatal(err)
}

printResponse(resp)

เปลือกหอย

MIME_TYPE=$(file -b --mime-type "${IMG_PATH_2}")
NUM_BYTES=$(wc -c < "${IMG_PATH_2}")
DISPLAY_NAME=TEXT

tmp_header_file=upload-header.tmp

# Initial resumable request defining metadata.
# The upload url is in the response headers dump them to a file.
curl "${BASE_URL}/upload/v1beta/files?key=${GEMINI_API_KEY}" \
  -D upload-header.tmp \
  -H "X-Goog-Upload-Protocol: resumable" \
  -H "X-Goog-Upload-Command: start" \
  -H "X-Goog-Upload-Header-Content-Length: ${NUM_BYTES}" \
  -H "X-Goog-Upload-Header-Content-Type: ${MIME_TYPE}" \
  -H "Content-Type: application/json" \
  -d "{'file': {'display_name': '${DISPLAY_NAME}'}}" 2> /dev/null

upload_url=$(grep -i "x-goog-upload-url: " "${tmp_header_file}" | cut -d" " -f2 | tr -d "\r")
rm "${tmp_header_file}"

# Upload the actual bytes.
curl "${upload_url}" \
  -H "Content-Length: ${NUM_BYTES}" \
  -H "X-Goog-Upload-Offset: 0" \
  -H "X-Goog-Upload-Command: upload, finalize" \
  --data-binary "@${IMG_PATH_2}" 2> /dev/null > file_info.json

file_uri=$(jq ".file.uri" file_info.json)
echo file_uri=$file_uri

# Now generate content using that file
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=$GEMINI_API_KEY" \
    -H 'Content-Type: application/json' \
    -X POST \
    -d '{
      "contents": [{
        "parts":[
          {"text": "Can you tell me about the instruments in this photo?"},
          {"file_data":
            {"mime_type": "image/jpeg", 
            "file_uri": '$file_uri'}
        }]
        }]
       }' 2> /dev/null > response.json

cat response.json
echo

jq ".candidates[].content.parts[].text" response.json

เสียง

Python

from google import genai

client = genai.Client()
myfile = client.files.upload(file=media / "sample.mp3")
print(f"{myfile=}")

result = client.models.generate_content(
    model="gemini-2.0-flash", contents=[myfile, "Describe this audio clip"]
)
print(f"{result.text=}")

Node.js

// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const myfile = await ai.files.upload({
  file: path.join(media, "sample.mp3"),
  config: { mimeType: "audio/mpeg" },
});
console.log("Uploaded file:", myfile);

const result = await ai.models.generateContent({
  model: "gemini-2.0-flash",
  contents: createUserContent([
    createPartFromUri(myfile.uri, myfile.mimeType),
    "Describe this audio clip",
  ]),
});
console.log("result.text=", result.text);

Go

file, err := client.UploadFileFromPath(ctx, filepath.Join(testDataDir, "sample.mp3"), nil)
if err != nil {
	log.Fatal(err)
}
defer client.DeleteFile(ctx, file.Name)

model := client.GenerativeModel("gemini-1.5-flash")
resp, err := model.GenerateContent(ctx,
	genai.FileData{URI: file.URI},
	genai.Text("Describe this audio clip"))
if err != nil {
	log.Fatal(err)
}

printResponse(resp)

เปลือกหอย

MIME_TYPE=$(file -b --mime-type "${AUDIO_PATH}")
NUM_BYTES=$(wc -c < "${AUDIO_PATH}")
DISPLAY_NAME=AUDIO

tmp_header_file=upload-header.tmp

# Initial resumable request defining metadata.
# The upload url is in the response headers dump them to a file.
curl "${BASE_URL}/upload/v1beta/files?key=${GEMINI_API_KEY}" \
  -D upload-header.tmp \
  -H "X-Goog-Upload-Protocol: resumable" \
  -H "X-Goog-Upload-Command: start" \
  -H "X-Goog-Upload-Header-Content-Length: ${NUM_BYTES}" \
  -H "X-Goog-Upload-Header-Content-Type: ${MIME_TYPE}" \
  -H "Content-Type: application/json" \
  -d "{'file': {'display_name': '${DISPLAY_NAME}'}}" 2> /dev/null

upload_url=$(grep -i "x-goog-upload-url: " "${tmp_header_file}" | cut -d" " -f2 | tr -d "\r")
rm "${tmp_header_file}"

# Upload the actual bytes.
curl "${upload_url}" \
  -H "Content-Length: ${NUM_BYTES}" \
  -H "X-Goog-Upload-Offset: 0" \
  -H "X-Goog-Upload-Command: upload, finalize" \
  --data-binary "@${AUDIO_PATH}" 2> /dev/null > file_info.json

file_uri=$(jq ".file.uri" file_info.json)
echo file_uri=$file_uri

# Now generate content using that file
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=$GEMINI_API_KEY" \
    -H 'Content-Type: application/json' \
    -X POST \
    -d '{
      "contents": [{
        "parts":[
          {"text": "Describe this audio clip"},
          {"file_data":{"mime_type": "audio/mp3", "file_uri": '$file_uri'}}]
        }]
       }' 2> /dev/null > response.json

cat response.json
echo

jq ".candidates[].content.parts[].text" response.json

ข้อความ

Python

from google import genai

client = genai.Client()
myfile = client.files.upload(file=media / "poem.txt")
print(f"{myfile=}")

result = client.models.generate_content(
    model="gemini-2.0-flash",
    contents=[myfile, "\n\n", "Can you add a few more lines to this poem?"],
)
print(f"{result.text=}")

Node.js

// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const myfile = await ai.files.upload({
  file: path.join(media, "poem.txt"),
});
console.log("Uploaded file:", myfile);

const result = await ai.models.generateContent({
  model: "gemini-2.0-flash",
  contents: createUserContent([
    createPartFromUri(myfile.uri, myfile.mimeType),
    "\n\n",
    "Can you add a few more lines to this poem?",
  ]),
});
console.log("result.text=", result.text);

Go

// Set MIME type explicitly for text files - the service may have difficulty
// distingushing between different MIME types of text files automatically.
file, err := client.UploadFileFromPath(ctx, filepath.Join(testDataDir, "poem.txt"), nil)
if err != nil {
	log.Fatal(err)
}
defer client.DeleteFile(ctx, file.Name)

model := client.GenerativeModel("gemini-1.5-flash")
resp, err := model.GenerateContent(ctx,
	genai.FileData{URI: file.URI},
	genai.Text("Can you add a few more lines to this poem?"))
if err != nil {
	log.Fatal(err)
}

printResponse(resp)

เปลือกหอย

MIME_TYPE=$(file -b --mime-type "${TEXT_PATH}")
NUM_BYTES=$(wc -c < "${TEXT_PATH}")
DISPLAY_NAME=TEXT

tmp_header_file=upload-header.tmp

# Initial resumable request defining metadata.
# The upload url is in the response headers dump them to a file.
curl "${BASE_URL}/upload/v1beta/files?key=${GEMINI_API_KEY}" \
  -D upload-header.tmp \
  -H "X-Goog-Upload-Protocol: resumable" \
  -H "X-Goog-Upload-Command: start" \
  -H "X-Goog-Upload-Header-Content-Length: ${NUM_BYTES}" \
  -H "X-Goog-Upload-Header-Content-Type: ${MIME_TYPE}" \
  -H "Content-Type: application/json" \
  -d "{'file': {'display_name': '${DISPLAY_NAME}'}}" 2> /dev/null

upload_url=$(grep -i "x-goog-upload-url: " "${tmp_header_file}" | cut -d" " -f2 | tr -d "\r")
rm "${tmp_header_file}"

# Upload the actual bytes.
curl "${upload_url}" \
  -H "Content-Length: ${NUM_BYTES}" \
  -H "X-Goog-Upload-Offset: 0" \
  -H "X-Goog-Upload-Command: upload, finalize" \
  --data-binary "@${TEXT_PATH}" 2> /dev/null > file_info.json

file_uri=$(jq ".file.uri" file_info.json)
echo file_uri=$file_uri

# Now generate content using that file
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=$GEMINI_API_KEY" \
    -H 'Content-Type: application/json' \
    -X POST \
    -d '{
      "contents": [{
        "parts":[
          {"text": "Can you add a few more lines to this poem?"},
          {"file_data":{"mime_type": "text/plain", "file_uri": '$file_uri'}}]
        }]
       }' 2> /dev/null > response.json

cat response.json
echo

jq ".candidates[].content.parts[].text" response.json

name=$(jq ".file.name" file_info.json)
# Get the file of interest to check state
curl https://generativelanguage.googleapis.com/v1beta/files/$name > file_info.json
# Print some information about the file you got
name=$(jq ".file.name" file_info.json)
echo name=$name
file_uri=$(jq ".file.uri" file_info.json)
echo file_uri=$file_uri

curl --request "DELETE" https://generativelanguage.googleapis.com/v1beta/files/$name?key=$GEMINI_API_KEY

วิดีโอ

Python

from google import genai
import time

client = genai.Client()
# Video clip (CC BY 3.0) from https://peach.blender.org/download/
myfile = client.files.upload(file=media / "Big_Buck_Bunny.mp4")
print(f"{myfile=}")

# Videos need to be processed before you can use them.
while myfile.state.name == "PROCESSING":
    print("processing video...")
    time.sleep(5)
    myfile = client.files.get(name=myfile.name)

result = client.models.generate_content(
    model="gemini-2.0-flash", contents=[myfile, "Describe this video clip"]
)
print(f"{result.text=}")

Node.js

// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
let myfile = await ai.files.upload({
  file: path.join(media, "Big_Buck_Bunny.mp4"),
  config: { mimeType: "video/mp4" },
});
console.log("Uploaded video file:", myfile);

// Poll until the video file is completely processed (state becomes ACTIVE).
while (!myfile.state || myfile.state.toString() !== "ACTIVE") {
  console.log("Processing video...");
  console.log("File state: ", myfile.state);
  await sleep(5000);
  myfile = await ai.files.get({ name: myfile.name });
}

const result = await ai.models.generateContent({
  model: "gemini-2.0-flash",
  contents: createUserContent([
    createPartFromUri(myfile.uri, myfile.mimeType),
    "Describe this video clip",
  ]),
});
console.log("result.text=", result.text);

Go

file, err := client.UploadFileFromPath(ctx, filepath.Join(testDataDir, "earth.mp4"), nil)
if err != nil {
	log.Fatal(err)
}
defer client.DeleteFile(ctx, file.Name)

// Videos need to be processed before you can use them.
for file.State == genai.FileStateProcessing {
	log.Printf("processing %s", file.Name)
	time.Sleep(5 * time.Second)
	var err error
	if file, err = client.GetFile(ctx, file.Name); err != nil {
		log.Fatal(err)
	}
}
if file.State != genai.FileStateActive {
	log.Fatalf("uploaded file has state %s, not active", file.State)
}

model := client.GenerativeModel("gemini-1.5-flash")
resp, err := model.GenerateContent(ctx,
	genai.FileData{URI: file.URI},
	genai.Text("Describe this video clip"))
if err != nil {
	log.Fatal(err)
}

printResponse(resp)

เปลือกหอย

MIME_TYPE=$(file -b --mime-type "${VIDEO_PATH}")
NUM_BYTES=$(wc -c < "${VIDEO_PATH}")
DISPLAY_NAME=VIDEO_PATH

# Initial resumable request defining metadata.
# The upload url is in the response headers dump them to a file.
curl "${BASE_URL}/upload/v1beta/files?key=${GEMINI_API_KEY}" \
  -D upload-header.tmp \
  -H "X-Goog-Upload-Protocol: resumable" \
  -H "X-Goog-Upload-Command: start" \
  -H "X-Goog-Upload-Header-Content-Length: ${NUM_BYTES}" \
  -H "X-Goog-Upload-Header-Content-Type: ${MIME_TYPE}" \
  -H "Content-Type: application/json" \
  -d "{'file': {'display_name': '${DISPLAY_NAME}'}}" 2> /dev/null

upload_url=$(grep -i "x-goog-upload-url: " "${tmp_header_file}" | cut -d" " -f2 | tr -d "\r")
rm "${tmp_header_file}"

# Upload the actual bytes.
curl "${upload_url}" \
  -H "Content-Length: ${NUM_BYTES}" \
  -H "X-Goog-Upload-Offset: 0" \
  -H "X-Goog-Upload-Command: upload, finalize" \
  --data-binary "@${VIDEO_PATH}" 2> /dev/null > file_info.json

file_uri=$(jq ".file.uri" file_info.json)
echo file_uri=$file_uri

state=$(jq ".file.state" file_info.json)
echo state=$state

# Ensure the state of the video is 'ACTIVE'
while [[ "($state)" = *"PROCESSING"* ]];
do
  echo "Processing video..."
  sleep 5
  # Get the file of interest to check state
  curl https://generativelanguage.googleapis.com/v1beta/files/$name > file_info.json
  state=$(jq ".file.state" file_info.json)
done

# Now generate content using that file
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=$GEMINI_API_KEY" \
    -H 'Content-Type: application/json' \
    -X POST \
    -d '{
      "contents": [{
        "parts":[
          {"text": "Describe this video clip"},
          {"file_data":{"mime_type": "video/mp4", "file_uri": '$file_uri'}}]
        }]
       }' 2> /dev/null > response.json

cat response.json
echo

jq ".candidates[].content.parts[].text" response.json

PDF

Python

from google import genai

client = genai.Client()
sample_pdf = client.files.upload(file=media / "test.pdf")
response = client.models.generate_content(
    model="gemini-2.0-flash",
    contents=["Give me a summary of this pdf file.", sample_pdf],
)
print(response.text)

เนื้อหาการตอบกลับ

คำตอบสำหรับ media.upload

หากทำสำเร็จ เนื้อหาการตอบกลับจะมีข้อมูลซึ่งมีโครงสร้างดังต่อไปนี้

ฟิลด์
file object (File)

ข้อมูลเมตาของไฟล์ที่สร้าง

การแสดง JSON
{
  "file": {
    object (File)
  }
}

เมธอด: files.get

รับข้อมูลเมตาของ File ที่ระบุ

ปลายทาง

get https://generativelanguage.googleapis.com/v1beta/{name=files/*}

พารามิเตอร์เส้นทาง

name string

ต้องระบุ ชื่อของ File ที่จะรับ ตัวอย่าง: files/abc-123 อยู่ในรูปแบบ files/{file}

เนื้อหาของคำขอ

เนื้อหาของคำขอต้องว่างเปล่า

ตัวอย่างคำขอ

Python

from google import genai

client = genai.Client()
myfile = client.files.upload(file=media / "poem.txt")
file_name = myfile.name
print(file_name)  # "files/*"

myfile = client.files.get(name=file_name)
print(myfile)

Node.js

// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const myfile = await ai.files.upload({
  file: path.join(media, "poem.txt"),
});
const fileName = myfile.name;
console.log(fileName);

const fetchedFile = await ai.files.get({ name: fileName });
console.log(fetchedFile);

Go

file, err := client.UploadFileFromPath(ctx, filepath.Join(testDataDir, "personWorkingOnComputer.jpg"), nil)
if err != nil {
	log.Fatal(err)
}
defer client.DeleteFile(ctx, file.Name)

gotFile, err := client.GetFile(ctx, file.Name)
if err != nil {
	log.Fatal(err)
}
fmt.Println("Got file:", gotFile.Name)

model := client.GenerativeModel("gemini-1.5-flash")
resp, err := model.GenerateContent(ctx,
	genai.FileData{URI: file.URI},
	genai.Text("Describe this image"))
if err != nil {
	log.Fatal(err)
}

printResponse(resp)

เปลือกหอย

name=$(jq ".file.name" file_info.json)
# Get the file of interest to check state
curl https://generativelanguage.googleapis.com/v1beta/files/$name > file_info.json
# Print some information about the file you got
name=$(jq ".file.name" file_info.json)
echo name=$name
file_uri=$(jq ".file.uri" file_info.json)
echo file_uri=$file_uri

เนื้อหาการตอบกลับ

หากทำสำเร็จ เนื้อหาการตอบกลับจะมีอินสแตนซ์ File

เมธอด: files.list

แสดงข้อมูลเมตาของFileที่โปรเจ็กต์ที่ส่งคำขอเป็นเจ้าของ

ปลายทาง

get https://generativelanguage.googleapis.com/v1beta/files

พารามิเตอร์การค้นหา

pageSize integer

ไม่บังคับ จำนวน File สูงสุดที่จะแสดงต่อหน้า หากไม่ได้ระบุ ระบบจะใช้ 10 เป็นค่าเริ่มต้น pageSize สูงสุดคือ 100

pageToken string

ไม่บังคับ โทเค็นหน้าเว็บจากการเรียกใช้ files.list ก่อนหน้านี้

เนื้อหาของคำขอ

เนื้อหาของคำขอต้องว่างเปล่า

ตัวอย่างคำขอ

Python

from google import genai

client = genai.Client()
print("My files:")
for f in client.files.list():
    print("  ", f.name)

Node.js

// Make sure to include the following import:
// import {GoogleGenAI} from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
console.log("My files:");
// Using the pager style to list files
const pager = await ai.files.list({ config: { pageSize: 10 } });
let page = pager.page;
const names = [];
while (true) {
  for (const f of page) {
    console.log("  ", f.name);
    names.push(f.name);
  }
  if (!pager.hasNextPage()) break;
  page = await pager.nextPage();
}

Go

iter := client.ListFiles(ctx)
for {
	ifile, err := iter.Next()
	if err == iterator.Done {
		break
	}
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(ifile.Name)
}

เปลือกหอย

echo "My files: "

curl "https://generativelanguage.googleapis.com/v1beta/files?key=$GEMINI_API_KEY"

เนื้อหาการตอบกลับ

คำตอบสำหรับ files.list

หากทำสำเร็จ เนื้อหาการตอบกลับจะมีข้อมูลซึ่งมีโครงสร้างดังต่อไปนี้

ฟิลด์
files[] object (File)

รายการ File

nextPageToken string

โทเค็นที่ส่งเป็น pageToken ไปยังการเรียกใช้ files.list ถัดไปได้

การแสดง JSON
{
  "files": [
    {
      object (File)
    }
  ],
  "nextPageToken": string
}

วิธีการ: files.delete

ลบ File

ปลายทาง

ลบ https://generativelanguage.googleapis.com/v1beta/{name=files/*}

พารามิเตอร์เส้นทาง

name string

ต้องระบุ ชื่อ File ที่จะลบ ตัวอย่าง: files/abc-123 อยู่ในรูปแบบ files/{file}

เนื้อหาของคำขอ

เนื้อหาของคำขอต้องว่างเปล่า

ตัวอย่างคำขอ

Python

from google import genai

client = genai.Client()
myfile = client.files.upload(file=media / "poem.txt")

client.files.delete(name=myfile.name)

try:
    result = client.models.generate_content(
        model="gemini-2.0-flash", contents=[myfile, "Describe this file."]
    )
    print(result)
except genai.errors.ClientError:
    pass

Node.js

// The Gen AI SDK for TypeScript and JavaScript is in preview.
// Some features have not been implemented.

Go

file, err := client.UploadFileFromPath(ctx, filepath.Join(testDataDir, "personWorkingOnComputer.jpg"), nil)
if err != nil {
	log.Fatal(err)
}
defer client.DeleteFile(ctx, file.Name)

gotFile, err := client.GetFile(ctx, file.Name)
if err != nil {
	log.Fatal(err)
}
fmt.Println("Got file:", gotFile.Name)

model := client.GenerativeModel("gemini-1.5-flash")
resp, err := model.GenerateContent(ctx,
	genai.FileData{URI: file.URI},
	genai.Text("Describe this image"))
if err != nil {
	log.Fatal(err)
}

printResponse(resp)

เปลือกหอย

curl --request "DELETE" https://generativelanguage.googleapis.com/v1beta/files/$name?key=$GEMINI_API_KEY

เนื้อหาการตอบกลับ

หากทำสำเร็จ เนื้อหาการตอบกลับจะเป็นออบเจ็กต์ JSON ว่าง

ทรัพยากร REST: files

ทรัพยากร: ไฟล์

ไฟล์ที่อัปโหลดไปยัง API รหัสถัดไป: 15

ฟิลด์
name string

เปลี่ยนแปลงไม่ได้ ตัวระบุ ชื่อทรัพยากร File รหัส (ชื่อที่ไม่รวมส่วนนำหน้า "files/") ประกอบด้วยอักขระที่เป็นตัวอักษรและตัวเลขคละกันหรือขีดกลาง (-) ได้สูงสุด 40 อักขระ และต้องไม่ขึ้นต้นหรือลงท้ายด้วยขีดกลาง หากชื่อว่างเปล่าเมื่อสร้าง ระบบจะสร้างชื่อที่ไม่ซ้ำกัน ตัวอย่าง: files/123-456

displayName string

ไม่บังคับ ชื่อที่แสดงที่มนุษย์อ่านได้สำหรับ File ชื่อที่แสดงต้องมีความยาวไม่เกิน 512 อักขระ ซึ่งรวมถึงการเว้นวรรค ตัวอย่างเช่น "Welcome Image"

mimeType string

เอาต์พุตเท่านั้น ประเภท MIME ของไฟล์

sizeBytes string (int64 format)

เอาต์พุตเท่านั้น ขนาดของไฟล์ในหน่วยไบต์

createTime string (Timestamp format)

เอาต์พุตเท่านั้น การประทับเวลาที่สร้าง File

ใช้ RFC 3339 ซึ่งเอาต์พุตที่สร้างขึ้นจะเป็นรูปแบบ Z-normalized เสมอ และใช้ตัวเลขทศนิยม 0, 3, 6 หรือ 9 ระบบยังยอมรับออฟเซตอื่นๆ นอกเหนือจาก "Z" ด้วย ตัวอย่างเช่น "2014-10-02T15:01:23Z", "2014-10-02T15:01:23.045123456Z" หรือ "2014-10-02T15:01:23+05:30"

updateTime string (Timestamp format)

เอาต์พุตเท่านั้น การประทับเวลาที่อัปเดต File ครั้งล่าสุด

ใช้ RFC 3339 ซึ่งเอาต์พุตที่สร้างขึ้นจะเป็นรูปแบบ Z-normalized เสมอ และใช้ตัวเลขทศนิยม 0, 3, 6 หรือ 9 ระบบยังยอมรับออฟเซตอื่นๆ นอกเหนือจาก "Z" ด้วย ตัวอย่างเช่น "2014-10-02T15:01:23Z", "2014-10-02T15:01:23.045123456Z" หรือ "2014-10-02T15:01:23+05:30"

expirationTime string (Timestamp format)

เอาต์พุตเท่านั้น การประทับเวลาที่ระบบจะลบ File ตั้งค่าเฉพาะในกรณีที่มีกำหนดเวลาให้ File หมดอายุ

ใช้ RFC 3339 ซึ่งเอาต์พุตที่สร้างขึ้นจะเป็นรูปแบบ Z-normalized เสมอ และใช้ตัวเลขทศนิยม 0, 3, 6 หรือ 9 ระบบยังยอมรับออฟเซตอื่นๆ นอกเหนือจาก "Z" ด้วย ตัวอย่างเช่น "2014-10-02T15:01:23Z", "2014-10-02T15:01:23.045123456Z" หรือ "2014-10-02T15:01:23+05:30"

sha256Hash string (bytes format)

เอาต์พุตเท่านั้น แฮช SHA-256 ของไบต์ที่อัปโหลด

สตริงที่เข้ารหัส Base64

uri string

เอาต์พุตเท่านั้น URI ของ File

downloadUri string

เอาต์พุตเท่านั้น รหัส URI ของไฟล์ File

state enum (State)

เอาต์พุตเท่านั้น สถานะการประมวลผลของไฟล์

source enum (Source)

แหล่งที่มาของไฟล์

error object (Status)

เอาต์พุตเท่านั้น สถานะข้อผิดพลาดหากการประมวลผลไฟล์ไม่สำเร็จ

metadata Union type
ข้อมูลเมตาของไฟล์ metadata ต้องเป็นค่าใดค่าหนึ่งต่อไปนี้เท่านั้น
videoMetadata object (VideoMetadata)

เอาต์พุตเท่านั้น ข้อมูลเมตาของวิดีโอ

การแสดง JSON
{
  "name": string,
  "displayName": string,
  "mimeType": string,
  "sizeBytes": string,
  "createTime": string,
  "updateTime": string,
  "expirationTime": string,
  "sha256Hash": string,
  "uri": string,
  "downloadUri": string,
  "state": enum (State),
  "source": enum (Source),
  "error": {
    object (Status)
  },

  // metadata
  "videoMetadata": {
    object (VideoMetadata)
  }
  // Union type
}

VideoMetadata

ข้อมูลเมตาของวิดีโอ File

ฟิลด์
videoDuration string (Duration format)

ระยะเวลาของวิดีโอ

ระยะเวลาเป็นวินาทีที่มีเศษทศนิยมได้สูงสุด 9 หลัก โดยลงท้ายด้วย s เช่น "3.5s"

การแสดง JSON
{
  "videoDuration": string
}

รัฐ

สถานะสำหรับวงจรของไฟล์

Enum
STATE_UNSPECIFIED ค่าเริ่มต้น ระบบจะใช้ค่านี้หากไม่ได้ระบุสถานะ
PROCESSING ระบบกําลังประมวลผลไฟล์และยังไม่สามารถใช้ไฟล์ดังกล่าวเพื่อการอนุมาน
ACTIVE ไฟล์ได้รับการประมวลผลและพร้อมสำหรับการอนุมาน
FAILED ประมวลผลไฟล์ไม่สำเร็จ

แหล่งที่มา

Enum
SOURCE_UNSPECIFIED ใช้ในกรณีที่ไม่ได้ระบุแหล่งที่มา
UPLOADED บ่งบอกว่าผู้ใช้อัปโหลดไฟล์
GENERATED ระบุว่าไฟล์สร้างขึ้นโดย Google

สถานะ

ประเภท Status จะกำหนดรูปแบบข้อผิดพลาดเชิงตรรกะที่เหมาะสมกับสภาพแวดล้อมการเขียนโปรแกรมต่างๆ ซึ่งรวมถึง REST API และ RPC API gRPC ใช้โปรโตคอลนี้ ข้อความ Status แต่ละรายการมีข้อมูล 3 รายการ ได้แก่ รหัสข้อผิดพลาด ข้อความแสดงข้อผิดพลาด และรายละเอียดข้อผิดพลาด

ดูข้อมูลเพิ่มเติมเกี่ยวกับรูปแบบข้อผิดพลาดนี้และวิธีจัดการได้ในคู่มือการออกแบบ API

ฟิลด์
code integer

รหัสสถานะ ซึ่งควรเป็นค่า enum ของ google.rpc.Code

message string

ข้อความแสดงข้อผิดพลาดที่แสดงต่อนักพัฒนาแอป ซึ่งควรเป็นภาษาอังกฤษ ข้อความแสดงข้อผิดพลาดที่แสดงต่อผู้ใช้ควรได้รับการแปลและส่งในช่อง google.rpc.Status.details หรือลูกค้าเป็นผู้แปล

details[] object

รายการข้อความที่มีรายละเอียดข้อผิดพลาด มีชุดประเภทข้อความทั่วไปสำหรับ API ต่างๆ ที่จะใช้ได้

ออบเจ็กต์ที่มีฟิลด์ประเภทใดก็ได้ ช่องเพิ่มเติม "@type" มี URI ที่ระบุประเภท ตัวอย่าง: { "id": 1234, "@type": "types.example.com/standard/id" }

การแสดง JSON
{
  "code": integer,
  "message": string,
  "details": [
    {
      "@type": string,
      field1: ...,
      ...
    }
  ]
}