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 =
['image/*'].freeze
FILE_TYPES_VIDEO =
['video/*'].freeze

Instance Method Summary collapse

Instance Method Details

#file_s3_uploader(options = {}) ⇒ Object

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



63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/helpers/uppy_s3_uploader_helper.rb', line 63

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 = {}) ⇒ Object

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



137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'app/helpers/uppy_s3_uploader_helper.rb', line 137

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 = {}) ⇒ Object

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



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

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 = {}) ⇒ Object

Lead form sketch/document uploads (WWW public site)
Used on: /contact, /quote pages
Note: Orphaned uploads (user removes file or abandons form) are cleaned up by
PurgeExpiredUploadsWorker after 7 days.

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.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/helpers/uppy_s3_uploader_helper.rb', line 84

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 = {}) ⇒ Object

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



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/helpers/uppy_s3_uploader_helper.rb', line 43

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

#uppy_s3_uploader(options = {}) ⇒ Object

Render the uppy S3 uploader partial with the given options



33
34
35
# File 'app/helpers/uppy_s3_uploader_helper.rb', line 33

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

#video_s3_uploader(options = {}) ⇒ Object

Video uploads (CRM)
For attaching video files to records



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'app/helpers/uppy_s3_uploader_helper.rb', line 121

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