Module: UppyS3UploaderHelper

Included in:
Www::UploadsController
Defined in:
app/helpers/uppy_s3_uploader_helper.rb

Overview

Helper methods for rendering Uppy S3 direct upload components.

All uploaders use direct-to-S3 uploads via presigned URLs, bypassing the Rails server
for better performance with large files. The Upload record is created after the S3
upload completes via the upload_complete endpoint.

Usage:
<%= rma_image_s3_uploader(@rma) %>
<%= lead_sketch_s3_uploader(height: 150) %>
<%= file_s3_uploader(max_files: 5, category: 'document') %>

Constant Summary collapse

MAX_FILE_SIZE =

Maximum file size for all uploaders (250MB handles CAD files, large images, videos)

250 * 1024 * 1024
DEFAULT_MAX_FILES =

Default number of files allowed per upload session

10
FILE_TYPES_ANY =

File type restrictions

['*/*'].freeze
FILE_TYPES_IMAGES =

File types images.

['image/*'].freeze
FILE_TYPES_VIDEO =

File types video.

['video/*'].freeze

Instance Method Summary collapse

Instance Method Details

#file_s3_uploader(options = {}) ⇒ String

General file uploads (CRM)
Used for ad-hoc file attachments

Parameters:

  • options (Hash) (defaults to: {})

    overrides for the defaults below (see #uppy_s3_uploader for all keys)

Options Hash (options):

  • max_files (Integer)

    maximum number of files (default: 5)

  • allowed_file_types (Array<String>)

    accepted MIME type patterns (default: any)

  • height (Integer)

    height of the uploader drop area in pixels

  • note (String)

    helper text shown inside the uploader

  • submit_button_text (String)

    label for the submit button

  • form_url (String, Hash)

    URL the wrapping form submits to

  • category (String)

    upload category stored on the Upload record

Returns:

  • (String)

    the rendered uploader partial



135
136
137
138
139
140
141
142
143
144
145
146
# File 'app/helpers/uppy_s3_uploader_helper.rb', line 135

def file_s3_uploader(options = {})
  uppy_s3_uploader({
    max_files: 5,
    allowed_file_types: FILE_TYPES_ANY,
    hidden_field_name: 'upload_ids',
    auto_proceed: false,
    height: 300,
    note: 'Any file type up to 250MB each',
    submit_button_text: 'Upload Files',
    resource_name: 'upload'
  }.merge(options))
end

#image_s3_uploader(options = {}) ⇒ String

Multiple image uploads (CRM)
Used by ImageKit integration and general image galleries

Parameters:

  • options (Hash) (defaults to: {})

    overrides for the defaults below (see #uppy_s3_uploader for all keys)

Options Hash (options):

  • max_files (Integer)

    maximum number of files (default: 10)

  • allowed_file_types (Array<String>)

    accepted MIME type patterns (default: images)

  • height (Integer)

    height of the uploader drop area in pixels

  • note (String)

    helper text shown inside the uploader

  • submit_button_text (String)

    label for the submit button

  • form_url (String, Hash)

    URL the wrapping form submits to

Returns:

  • (String)

    the rendered uploader partial



240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'app/helpers/uppy_s3_uploader_helper.rb', line 240

def image_s3_uploader(options = {})
  uppy_s3_uploader({
    max_files: DEFAULT_MAX_FILES,
    allowed_file_types: FILE_TYPES_IMAGES,
    hidden_field_name: 'files[files_list]',
    auto_proceed: false,
    height: 400,
    note: 'Image files up to 250MB each',
    submit_button_text: 'Upload Images',
    form_url: { action: :create_multi },
    resource_name: 'files',
    manual_submit: false
  }.merge(options))
end

#large_file_s3_uploader(options = {}) ⇒ String

Large file uploads (CRM)
Single file mode for very large uploads

Parameters:

  • options (Hash) (defaults to: {})

    overrides for the defaults below (see #uppy_s3_uploader for all keys)

Options Hash (options):

  • max_files (Integer)

    maximum number of files (default: 1)

  • allowed_file_types (Array<String>)

    accepted MIME type patterns (default: any)

  • height (Integer)

    height of the uploader drop area in pixels

  • note (String)

    helper text shown inside the uploader

  • submit_button_text (String)

    label for the submit button

Returns:

  • (String)

    the rendered uploader partial



193
194
195
196
197
198
199
200
201
202
203
204
# File 'app/helpers/uppy_s3_uploader_helper.rb', line 193

def large_file_s3_uploader(options = {})
  uppy_s3_uploader({
    max_files: 1,
    allowed_file_types: FILE_TYPES_ANY,
    hidden_field_name: 'upload_ids',
    auto_proceed: true,
    height: 400,
    note: 'Large files up to 250MB',
    submit_button_text: 'Upload File',
    resource_name: 'upload'
  }.merge(options))
end

#lead_sketch_s3_uploader(options = {}) ⇒ String

Note:

Orphaned uploads (user removes file or abandons form) are cleaned up by

Lead form sketch/document uploads (WWW public site)
Used on: /contact, /quote pages

This helper renders Uppy directly (no lazy loading) with a native file input
fallback that shows if Uppy fails to initialize. This provides a bulletproof
upload experience for customers.
PurgeExpiredUploadsWorker after 7 days.

Parameters:

  • options (Hash) (defaults to: {})

    overrides for the defaults below (see #uppy_s3_uploader for all keys)

Options Hash (options):

  • max_files (Integer)

    maximum number of files (default: 10)

  • allowed_file_types (Array<String>)

    accepted MIME type patterns (default: any)

  • height (Integer)

    height of the uploader drop area in pixels

  • note (String)

    helper text shown inside the uploader

  • submit_button_text (String)

    label for the submit button

  • show_fallback (Boolean)

    render a native file input fallback (default: true)

Returns:

  • (String)

    the rendered uploader partial



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'app/helpers/uppy_s3_uploader_helper.rb', line 164

def lead_sketch_s3_uploader(options = {})
  uppy_s3_uploader({
    # WWW site uses separate upload endpoints (no CRM auth required)
    presigned_url_endpoint: presigned_url_www_uploads_path,
    upload_complete_endpoint: upload_complete_www_uploads_path,
    max_files: DEFAULT_MAX_FILES,
    allowed_file_types: FILE_TYPES_ANY,
    hidden_field_name: 'lead[sketch_drawings]',
    auto_proceed: true,
    height: 200,
    note: 'Attach images, PDFs, CAD files, or ZIPs (up to 250MB each)',
    submit_button_text: 'Upload Sketches',
    resource_name: 'lead',
    category: 'sketch',
    manual_submit: false,
    # Show native file input fallback for WWW pages - handles Uppy init failures
    show_fallback: true
  }.merge(options))
end

#rma_image_s3_uploader(rma, options = {}) ⇒ String

RMA photo attachments (CRM)
Used on: /rmas/:id/add_multiple_images

Parameters:

  • rma (Rma)

    the RMA the uploads attach to

  • options (Hash) (defaults to: {})

    overrides for the defaults below (see #uppy_s3_uploader for all keys)

Options Hash (options):

  • max_files (Integer)

    maximum number of files (default: 10)

  • allowed_file_types (Array<String>)

    accepted MIME type patterns (default: images)

  • height (Integer)

    height of the uploader drop area in pixels

  • note (String)

    helper text shown inside the uploader

  • submit_button_text (String)

    label for the submit button

  • category (String)

    upload category (default: 'photo')

Returns:

  • (String)

    the rendered uploader partial



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/helpers/uppy_s3_uploader_helper.rb', line 76

def rma_image_s3_uploader(rma, options = {})
  uppy_s3_uploader({
    max_files: DEFAULT_MAX_FILES,
    allowed_file_types: FILE_TYPES_IMAGES,
    hidden_field_name: 'rma[upload_ids]',
    auto_proceed: false,
    height: 400,
    note: 'Image files up to 250MB each',
    submit_button_text: 'Upload & Attach Images',
    form_url: do_add_multiple_images_rma_path(rma),
    resource_name: 'rma',
    resource_type: 'Rma',
    resource_id: rma.id,
    category: 'photo',
    manual_submit: true
  }.merge(options))
end

#rma_item_image_s3_uploader(rma_item, category: 'photo', note: nil, **options) ⇒ String

RMA item photo attachments (CRM)
Used on: /rmas/:id — per-item inspection photos. Pass category: to
distinguish e.g. 'photo' (non-resalable) from 'not_returned_photo'.

Parameters:

  • rma_item (RmaItem)

    the RMA item the uploads attach to

  • category (String) (defaults to: 'photo')

    upload category stored on the Upload record

  • note (String, nil) (defaults to: nil)

    helper text shown inside the uploader (a default is used when nil)

  • options (Hash)

    overrides for the defaults below (see #uppy_s3_uploader for all keys)

Options Hash (**options):

  • max_files (Integer)

    maximum number of files (default: 10)

  • allowed_file_types (Array<String>)

    accepted MIME type patterns (default: images)

  • height (Integer)

    height of the uploader drop area in pixels

  • submit_button_text (String)

    label for the submit button

Returns:

  • (String)

    the rendered uploader partial



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/helpers/uppy_s3_uploader_helper.rb', line 106

def rma_item_image_s3_uploader(rma_item, category: 'photo', note: nil, **options)
  uppy_s3_uploader({
    max_files: DEFAULT_MAX_FILES,
    allowed_file_types: FILE_TYPES_IMAGES,
    hidden_field_name: 'rma_item[upload_ids]',
    auto_proceed: true,
    height: 250,
    note: note || 'Attach photos showing why the item is non-resalable',
    submit_button_text: 'Attach Photos',
    form_url: do_add_rma_item_images_rma_path(rma_item.rma, rma_item_id: rma_item.id, category: category),
    resource_name: 'rma_item',
    resource_type: 'RmaItem',
    resource_id: rma_item.id,
    category: category,
    manual_submit: false
  }.merge(options))
end

#uppy_s3_uploader(options = {}) ⇒ String

Render the uppy S3 uploader partial with the given options

Parameters:

  • options (Hash) (defaults to: {})

    locals for the shared/uppy_s3_uploader partial, merged over the base defaults

Options Hash (options):

  • presigned_url_endpoint (String)

    URL that issues S3 presigned URLs

  • upload_complete_endpoint (String)

    URL notified when an upload completes

  • max_file_size (Integer)

    maximum allowed file size in bytes

  • max_files (Integer)

    maximum number of files per upload session

  • allowed_file_types (Array<String>)

    accepted MIME type patterns (e.g. ['image/*'])

  • hidden_field_name (String)

    name of the hidden input collecting uploaded ids

  • auto_proceed (Boolean)

    whether uploads start immediately when files are dropped

  • height (Integer)

    height of the uploader drop area in pixels

  • note (String)

    helper text shown inside the uploader

  • submit_button_text (String)

    label for the submit button

  • form_url (String, Hash)

    URL the wrapping form submits to

  • form_method (Symbol)

    HTTP method for the wrapping form

  • form_local (Boolean)

    whether the wrapping form submits locally (no remote)

  • resource_name (String)

    param namespace the upload ids are submitted under

  • resource_type (String)

    class name of the record the upload attaches to

  • resource_id (Integer)

    id of the record the upload attaches to

  • category (String)

    upload category stored on the Upload record

  • manual_submit (Boolean)

    whether the user must submit the form explicitly

  • show_fallback (Boolean)

    render a native file input fallback if Uppy fails to initialize

Returns:

  • (String)

    the rendered uploader partial



57
58
59
# File 'app/helpers/uppy_s3_uploader_helper.rb', line 57

def uppy_s3_uploader(options = {})
  render 'shared/uppy_s3_uploader', base_uploader_options.merge(options)
end

#video_s3_uploader(options = {}) ⇒ String

Video uploads (CRM)
For attaching video files to records

Parameters:

  • options (Hash) (defaults to: {})

    overrides for the defaults below (see #uppy_s3_uploader for all keys)

Options Hash (options):

  • max_files (Integer)

    maximum number of files (default: 1)

  • allowed_file_types (Array<String>)

    accepted MIME type patterns (default: video)

  • height (Integer)

    height of the uploader drop area in pixels

  • note (String)

    helper text shown inside the uploader

  • submit_button_text (String)

    label for the submit button

  • category (String)

    upload category (default: 'video')

Returns:

  • (String)

    the rendered uploader partial



216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'app/helpers/uppy_s3_uploader_helper.rb', line 216

def video_s3_uploader(options = {})
  uppy_s3_uploader({
    max_files: 1,
    allowed_file_types: FILE_TYPES_VIDEO,
    hidden_field_name: 'video[upload_id]',
    auto_proceed: true,
    height: 400,
    note: 'Video files up to 250MB',
    submit_button_text: 'Upload Video',
    resource_name: 'video',
    category: 'video'
  }.merge(options))
end