Skip to main content

Overview

The JoyDoc SDK provides comprehensive image upload functionality through image fields, supporting both single and multiple image uploads with flexible handling options. Architecture Overview When users interact with image fields, the SDK triggers upload events that your application must handle by implementing upload handlers. Flow:
  1. User selects image field → SDK creates upload event
  2. Your upload handler receives the event
  3. You handle the image processing and pass the image url back to SDK
  4. SDK updates the form with the provided URLs

Upload Methods

JoyDoc provides two methods for handling image uploads:
  • onFileUploadAsync (configured in field settings)
  • onUploadAsync (configured in JoyDoc component props)

Basic Implementation Examples

onFieldUploadAsync You can also configure onFileUploadAsync via field settings as documented in the Joyfill Customize Settings guide:

onUploadAsync

Configure upload handling at the document level:

Parameters

Both methods receive the same parameters:
  • params: Object containing field/document metadata
    • params.fileId: The file ID
    • params.pageId: The page ID
    • params.fieldId: The field ID
    • params.fieldPositionId: The field position ID
    • params.fieldIdentifier: The field identifier
    • params.documentId: The document ID
    • params.documentIdentifier: The document identifier
  • fileUploads: Array of File objects to be uploaded

Return Value

Both methods should return an array of upload results. Each result should contain:
  • _id: Unique identifier for the uploaded file
  • url: URL where the file can be accessed
  • fileName: Original filename
  • fileSize: Size of the file in bytes

Complete Working Examples

Example 1: onFileUploadAsync

Here’s a complete working example using onFileUploadAsync:

Example 2: onUploadAsync

Here’s a complete working example using onUploadAsync:

Setup steps

Step 1: Create Joyfill Account
  • To begin working with Joyfill, go to Joyfill’s Platform and create an account (jump to step 2 if you already have an account).
  • By creating an account you will add yourself as the first user to your newly created Joyfill Organization and be placed inside the Joyfill Manager.
Step 2: Generate Your userAccessToken
  • Once you’re inside the Joyfill Manager you will want to select from the top navigation bar Settings & Users -> Manager Users -> and click “Access Tokens” button next to your user.
  • Once the modal appears select “Add Access Token”. Copy and securely store your access token for later use.
Step3 Api Url
  • The Api url is http://api-joy.joyfill.io

Helper Functions

These utility functions are used in both upload methods:

getDataUriForFileUpload

Converts a File object to a data URI string:

uploadFileAsync

Uploads a data URI to the server:

getHeaders

Returns the necessary headers for API requests: