api.files

file.save()

file.save({ storageId, path, localOnly }) → Promise<Result>

يكتب الملف ، الى الحساب ، الى القرص المحلي ، او كليهما ، ويُدعى هنا ويكلِّف ذلك مبلغا .

POST /api/files/save1 creditrefunded if the write fails
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

المعاملات

storageIdstring

أيّ مخزن سيكتب إليه، بدونه الحساب افتراضيّ

pathstring

Node فقط. اكتب أيضاً إلى هذا المسار المحلي، إنشاء المجلّدات.

localOnlyboolean

مع مع مع path: كتابة محلياً و توقفلا شيء يُرفع، لا شيء يُحاسب

الطرق الثلاث لاستخدامه

// 1. To the account — the usual one
await file.save();

// 2. To the account AND to this machine, in one call
await file.save({ path: "./out/report.md" });

// 3. To this machine only — no request, no credit
await file.save({ path: "./out/report.md", localOnly: true });
// { ok: true, status: "saved_local", path: "./out/report.md" }
# 1. To the account — the usual one
file.save()

# 2. To the account AND to this machine, in one call
file.save(path="./out/report.md")

# 3. To this machine only — no request, no credit
file.save(path="./out/report.md", local_only=True)
# {"ok": True, "status": "saved_local", "path": "./out/report.md"}
لا يُفِض هذا المُ_____ لا ي

إذا كان الطريق لا يمكن كتابته، SDK تحذيرات على لوحة المفاتيح واكمل إلى التحميل تحقق من الملف بنفسك عندما تكون النسخة المحلية هي التي تهم - مجلد للقراءة فقط لن يرفع.

القيمة المُعادة

{
  ok: true,
  status: "saved",
  sourceId: "…",            // how you find it again
  name: "report.md",
  category: "document",
  mimeType: "text/markdown",
  location: "object",       // the kind of storage it landed in
  metadata: {
    size: 2048,
    storageId: "…",
    remainingBytes: null,   // what is left, when the storage tracks it
    durationMs: 260
  },
  creditsUsed: 1
}
{
    "ok": True,
    "status": "saved",
    "sourceId": "…",            # how you find it again
    "name": "report.md",
    "category": "document",
    "mimeType": "text/markdown",
    "location": "object",       # the kind of storage it landed in
    "metadata": {
        "size": 2048,
        "storageId": "…",
        "remainingBytes": None,   # what is left, when the storage tracks it
        "durationMs": 260,
    },
    "creditsUsed": 1,
}

The object learns from it: file.sourceId, file.location and file.metadata are set, which is what makes update() possible straight afterwards.

يُنتقِشُ أين يذهب

// The account's default
await file.save();

// A storage you named
const all = await api.storage.list();
const archive = all.find((s) => s.label === "Archive");
await file.save({ storageId: archive.id });
# The account's default
file.save()

# A storage you named
archive = next(s for s in api.storage.list() if s.label == "Archive")
file.save(storage_id=archive.id)
نوعاحفظ إلى هذا
:: قاعدة بياناتنعم - تُحفظ حسابات الحسابات
نظام الملفاتSerرُفض: storage_is_local
ميكرو ميكرو ميكرو ميكرو ميكرورُفض: storage_is_local

يأتي الرفض ثالثاً الحساب هو من ليس فشل إلى إعادة المحاولة هذه الأجهزة حفظ ملفات و طريقة كتابتها من جهاز.

الائتمان، وعندما يعود

  • أحد الحسابات تؤخذ قبل الكتابة
  • إذا كان هذا الخط يُكتب ثمّ إلى مُرْفِض في و تحصل على 502 storage_failed.
  • فالرفض الذي يحدث أولا - لا يوجد تخزين، ولا مخزن محلي، ولا محتوى - لا يكلف شيئا على الإطلاق.

يجري العمل على مستند بعد أن تحصل على جوابك

عندما يكون التصنيف هو: document، النص هو مُفهَرس للبحث الدلالي بمجرد إرسال الرد. لذا فإن الملف يمكن قراءته فوراً و إيجاده في كل مرحلة على حدة بعد لحظة.

لا تبحث عن شيء حفظته للتو، في نفس نفس نفس نفس

( ١ بطرس ٣ : ١ ) فَهُوَ يَحْتَاجُ إِلَى ٱلْمَحَبَّةِ بِٱلْمَسِيحِيِّينَ ٱلْمُتَوَقِّعِينَ .

الأخطاء

الرمزالحالةمتى)
— (يُطلَق محليًا)—غير معرف أو لاغي.لم تــ
missing_file_content400لم يصل إلى الخادم ملف أو محتوى نص.لم تــ
storage_not_found404الحساب ليس لديه تخزين على الإطلاق.لم تــ
storage_is_local400الهدف هو حاسوب أو هاتفلم تــ
not_enough_credits402الرصيد لن يغطيهلم تــ
storage_failed502الـ كتابة مُنتَهِل.مبعثــــر
import { IaGenifyError } from "iagenify";

try {
  await file.save({ storageId });
} catch (err) {
  if (err instanceof IaGenifyError && err.code === "storage_is_local") {
    // That storage is a device. Write it there instead.
    const device = await api.storage.get({ id: storageId });
    await device.files.write("report.md", file.content);
  } else throw err;
}
from iagenify import IaGenifyError

try:
    file.save(storage_id=storage_id)
except IaGenifyError as error:
    if error.code != "storage_is_local":
        raise
    # That storage is a device. Write it there instead.
    device = api.storage.get(id=storage_id)
    device.files.write("report.md", file.content)