π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
feat: add attachment upload endpoint and related parameters
Pranav C79826b1ac7c7
diff --git a/packages/nocodb/src/services/api-docs/swaggerV3/templates/params.ts b/packages/nocodb/src/services/api-docs/swaggerV3/templates/params.tsindex f736e8b9b1..ba584d98cb 100644--- a/packages/nocodb/src/services/api-docs/swaggerV3/templates/params.ts+++ b/packages/nocodb/src/services/api-docs/swaggerV3/templates/params.ts@@ -1,4 +1,4 @@-import { isLinksOrLTAR, isSelfLinkCol } from 'nocodb-sdk';+import { isLinksOrLTAR, isSelfLinkCol, UITypes } from 'nocodb-sdk';import type { SwaggerColumn } from '../getSwaggerColumnMetasV3';import type { SwaggerView } from '~/services/api-docs/swaggerV3/getSwaggerJSONV3';@@ -161,3 +161,32 @@ export const viewIdParam = (views: SwaggerView[]) => {required: false,};};++export const attachmentFieldIdParam = (columns: SwaggerColumn[]) => {+ const attachmentColumnIds = [];+ const description = [+ '**Attachment Field Identifier** corresponding to the attachment field where you want to upload the file.\n\nAttachment Fields:',+ ];+ for (const { column } of columns) {+ // Only include attachment columns+ if (column.uidt !== UITypes.Attachment) continue;++ attachmentColumnIds.push(column.id);+ description.push(`* ${column.id} - ${column.title}`);+ }++ return {+ schema: {+ type: 'string',+ enum: attachmentColumnIds,+ },+ name: 'fieldId',+ in: 'path',+ required: true,+ description: description.join('\n'),+ };+};++export function hasAttachmentColumns(columns: SwaggerColumn[]): boolean {+ return columns.some(({ column }) => column.uidt === UITypes.Attachment);+}diff --git a/packages/nocodb/src/services/api-docs/swaggerV3/templates/paths.ts b/packages/nocodb/src/services/api-docs/swaggerV3/templates/paths.tsindex ea508788dd..6887022730 100644--- a/packages/nocodb/src/services/api-docs/swaggerV3/templates/paths.ts+++ b/packages/nocodb/src/services/api-docs/swaggerV3/templates/paths.ts@@ -1,6 +1,8 @@import { ModelTypes } from 'nocodb-sdk';import {+ attachmentFieldIdParam,fieldsParam,+ hasAttachmentColumns,linkFieldNameParam,nestedPageParam,pageParam,@@ -380,6 +382,102 @@ export const getModelPaths = async (},}: {}),++ ...(hasAttachmentColumns(ctx.columns)+ ? {+ [`/api/v3/data/${ctx.baseId}/${ctx.tableId}/records/{recordId}/fields/{fieldId}/upload`]:+ {+ parameters: [recordIdParam, attachmentFieldIdParam(ctx.columns)],+ post: {+ summary: 'Upload Attachment to Cell',+ operationId: `${ctx.tableName.toLowerCase()}-attachment-upload`,+ description:+ 'This API endpoint allows you to upload an attachment (base64 encoded) to a specific cell in a table. The attachment data includes content type, base64 encoded file, and filename.',+ tags: [ctx.tableName],+ requestBody: {+ required: true,+ content: {+ 'application/json': {+ schema: {+ type: 'object',+ properties: {+ contentType: {+ type: 'string',+ description:+ 'Content type of the file (e.g., image/png, application/pdf).',+ },+ file: {+ type: 'string',+ description: 'Base64 encoded file content.',+ },+ filename: {+ type: 'string',+ description: 'Original filename of the attachment.',+ },+ },+ required: ['contentType', 'file', 'filename'],+ },+ examples: {+ 'Example 1': {+ value: {+ contentType: 'image/png',+ file: 'iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==',+ filename: 'image.png',+ },+ },+ },+ },+ },+ },+ responses: {+ '200': {+ description: 'OK',+ content: {+ 'application/json': {+ schema: {+ type: 'object',+ properties: {+ id: {+ oneOf: [{ type: 'string' }, { type: 'number' }],+ description:+ 'Record identifier (primary key value)',+ },+ fields: {+ type: 'object',+ description: 'Updated record fields data',+ },+ },+ required: ['id'],+ },+ examples: {+ 'Example 1': {+ value: {+ id: 1,+ fields: {+ attachment_field: [+ {+ title: 'image.png',+ url: 'https://example.com/files/image.png',+ mimetype: 'image/png',+ size: 12345,+ icon: 'mdi-file-image',+ },+ ],+ },+ },+ },+ },+ },+ },+ },+ '400': {+ $ref: '#/components/responses/BadRequest',+ },+ },+ },+ },+ }+ : {}),});function getPaginatedResponseTypeV3(type: string) {