Files
onspring-api-docs/src/docs/version_002/resources/files/add_file/example.md
T
Stevan Freeborn 7ad0b30f34 feat: add Rust code examples and support for Rust syntax highlighting
- Added Rust syntax highlighting to the Fence component.
- Updated Markdoc functions to clone React elements with unique keys for copy and example sections.
- Included Rust code examples for various API endpoints in documentation:
  - `get_app_by_id`
  - `get_apps`
  - `get_apps_by_ids`
  - `connectivity`
  - `get_field_by_id`
  - `get_fields_by_app`
  - `get_fields_by_ids`
  - `add_file`
  - `delete_file_by_id`
  - `get_file_by_id`
  - `get_file_info_by_id`
  - `delete_list_value_by_id`
  - `save_list_value`
  - `delete_record_by_id`
  - `delete_records_by_ids`
  - `get_record_by_id`
  - `get_records_by_app`
  - `get_records_by_ids`
  - `get_records_by_query`
  - `save_record`
  - `get_report_by_id`
  - `get_reports_by_app`
2026-03-26 21:53:02 -05:00

2.8 KiB

Add a file to a record

{% code method="POST" heading="/Files" defaultLanguage="bash" %}

curl --location 'https://api.onspring.com/Files' \
--header 'X-ApiKey: 000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000' \
--form 'recordId="140"' \
--form 'fieldId="6989"' \
--form 'notes="Updating record with attachment."' \
--form 'modifiedDate=""' \
--form 'file=@"test-attachment.txt"'
using Onspring.API.SDK;
using Onspring.API.SDK.Models;
using System.IO;

var onspringClient = new OnspringClient(
  config.BaseUrl,
  config.ApiKey
);

var filePath = "test-attachment.txt";
var saveFileRequest = new SaveFileRequest
{
  FieldId = 6989,
  RecordId = 140,
  FileStream = File.OpenRead(filePath),
  FileName = Path.GetFileName(filePath),
  ModifiedDate = DateTime.UtcNow,
  Notes = "Updating record with attachment.",
  ContentType = "text/plain"
};

var saveResponse = await onspringClient.SaveFileAsync(saveFileRequest);
Console.WriteLine($"New File Id is: {saveResponse.Value.Id}");
import {
  OnspringClient,
  SaveFileRequest,
} from 'onspring-api-sdk';
import dotenv from 'dotenv';
import fs from 'fs';
dotenv.config();

const client = new OnspringClient(
  process.env.BASE_URL,
  process.env.API_KEY
);

const request = new SaveFileRequest(
  140,
  6989,
  'notes',
  new Date(),
  'test-attachment.txt',
  'text/plain',
  fs.createReadStream('test-attachment.txt')
);

const res = await client.saveFile(request);
const fileId = res.data.id;

console.log(fileId);
from OnspringApiSdk.OnspringClient import OnspringClient
from OnspringApiSdk.Models import SaveFileRequest
from configparser import ConfigParser

cfg = ConfigParser()
cfg.read('config.ini')

key = cfg['prod']['key']
url = cfg['prod']['url']

client = OnspringClient(url, key)
request = SaveFileRequest(
  recordId=140,
  fieldId=6989,
  fileName='test-attachment.txt',
  filePath='test-attachment.txt',
  contentType='text/plain',
  notes='Updating record with attachment.',
  modifiedDate=datetime.now()
)

response = client.SaveFile(request)

print(f'Status Code: {response.statusCode}')
print(f'File Id: {response.data.id}')
use onspring::{OnspringClient, SaveFileRequest};

let client = OnspringClient::builder(
  "000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000"
)
.build();

let request = SaveFileRequest {
  record_id: 140,
  field_id: 6989,
  notes: Some(
    "Updating record with attachment.".to_string()
  ),
  modified_date: Some(chrono::Utc::now()),
  file_name: "test-attachment.txt".to_string(),
  file_data: std::fs::read("test-attachment.txt")?,
  content_type: "text/plain".to_string(),
};

let response = client.upload_file(request).await?;

println!("New File Id is: {}", response.id);

{% /code %}

{% code heading="RESPONSE" defaultLanguage="json" %}

{
  "id": 1904
}

{% /code %}