@@ -42,13 +42,22 @@ interface IOnExecuteArguments {
4242
4343
4444 /**
45- *
46- * For safe uploading binary data, the data is splitted into multiple chunks
47- * to be uploaded sequentially.
45+ * For optimized porocessing, files are grouped into multiple chunks and uploaded sequentially.
4846 * This parameter defines the maximum size of each chunk (in bytes).
49- * Default to 15M.
47+ * A size of a single file can exceed this value, but should be up to maxFileSize;
48+ * Default: 15Mb.
49+ * Maximum: 37Mb.
5050 */
5151 maxChunkSize : number ;
52+
53+ /**
54+ * Limits the maximal allowed size of a single file (in bytes) (ContentDocument.ContentSize field)
55+ * Commonly, the SF API is limiting the max size of the API request to 52428800 bytes.
56+ * So, the maximal file size can't be greater then 37Mb. Larger files are ignored and not uploaded.
57+ * Default: 37Mb.
58+ * Maximum: 37Mb
59+ */
60+ maxFileSize : number ;
5261}
5362
5463interface IDataToImport {
@@ -87,7 +96,7 @@ export default class ExportFiles extends SfdmuRunAddonModule {
8796 break ;
8897
8998 default :
90- // TODO: Something to do whe is a regular sObject type
99+ // TODO: Something to do when it's a regular sObject type
91100 break ;
92101 }
93102
@@ -111,6 +120,17 @@ export default class ExportFiles extends SfdmuRunAddonModule {
111120 return ;
112121 }
113122
123+ // Default values
124+ args . maxFileSize = args . maxFileSize || CONSTANTS . DEFAULT_MAX_FILE_SIZE ;
125+ if ( args . maxFileSize > CONSTANTS . MAX_FILE_SIZE ) {
126+ args . maxFileSize = CONSTANTS . MAX_FILE_SIZE ;
127+ }
128+
129+ args . maxChunkSize = args . maxChunkSize || CONSTANTS . DEFAULT_MAX_CHUNK_SIZE ;
130+ if ( args . maxChunkSize > CONSTANTS . MAX_CHUNK_SIZE ) {
131+ args . maxChunkSize = CONSTANTS . MAX_CHUNK_SIZE ;
132+ }
133+
114134 // Get the relevant parent task
115135 let task = this . runtime . pluginJob . tasks . find ( task => task . sObjectName == context . objectName ) ;
116136
@@ -177,9 +197,17 @@ export default class ExportFiles extends SfdmuRunAddonModule {
177197
178198 await this . runtime . transferContentVersions ( this , versionsToProcess , args . maxChunkSize ) ;
179199
200+ const failedRecordsCount = versionsToProcess . filter ( item => item . isError ) . length ;
201+
180202 this . runtime . logFormattedInfo ( this , SFDMU_RUN_ADDON_MESSAGES . ExportFiles_ProcessedRecords ,
181203 String ( versionsToProcess . length ) ,
182- String ( versionsToProcess . filter ( item => item . isError ) . length ) ) ;
204+ String ( failedRecordsCount ) ) ;
205+
206+ if ( failedRecordsCount == versionsToProcess . length ) {
207+ // All content versions are failed => Nothing to process
208+ exportedFilesMap . clear ( ) ;
209+ versionsToProcess = [ ] ;
210+ }
183211 }
184212
185213
@@ -384,7 +412,7 @@ export default class ExportFiles extends SfdmuRunAddonModule {
384412 filteredByDocIdsByField ,
385413 'ContentVersion' ,
386414 sourceFiles . docIds ,
387- ' IsLatest = true' ) ;
415+ `( IsLatest = true) AND (ContentDocument.ContentSize <= ${ args . maxFileSize } )` ) ;
388416 if ( args . sourceWhere ) {
389417 queries = queries . map ( query => query . replace ( 'WHERE' , 'WHERE (' + args . sourceWhere + ') AND (' ) + ')' )
390418 }
0 commit comments