@@ -19,6 +19,17 @@ export type FileSaveOptions = FullOptions & {
1919 metadata ?: Record < string , any > ;
2020 tags ?: Record < string , any > ;
2121 directory ?: string ;
22+ /**
23+ * Overrides the server's `maxUploadSize` for this file upload. Requires the
24+ * master key (`useMasterKey: true`). The value uses the same format as the
25+ * server option (e.g. `'50mb'`, `'1gb'`).
26+ *
27+ * Only supported for Buffer and Stream source types. Files created from
28+ * base64 strings, number arrays, Blobs, or URIs do not support this option.
29+ *
30+ * Requires Parse Server >= 9.5.0.
31+ */
32+ maxUploadSize ?: string ;
2233} ;
2334export type FileSource =
2435 | {
@@ -309,6 +320,10 @@ class ParseFile {
309320 * }
310321 * });
311322 * </pre>
323+ * <li>maxUploadSize: Overrides the server's maxUploadSize for this upload.
324+ * Requires the master key. Only supported for Buffer and Stream source
325+ * types; files created from base64 strings, number arrays, Blobs, or URIs
326+ * do not support this option. Requires Parse Server >= 9.5.0.
312327 * </ul>
313328 * @returns {Promise | undefined } Promise that is resolved when the save finishes.
314329 */
@@ -333,7 +348,7 @@ class ParseFile {
333348 ( this . _tags && Object . keys ( this . _tags ) . length > 0 ) ||
334349 ! ! this . _directory ;
335350
336- if ( controller . saveBinary && ( this . _source . format === 'stream' || ! hasFileData ) ) {
351+ if ( controller . saveBinary && ( this . _source . format === 'stream' || ! hasFileData || options . maxUploadSize ) ) {
337352 // Binary upload via ajax (file data sent via headers for streams)
338353 this . _previousSave = controller
339354 . saveBinary ( this . _name , this . _source , options )
@@ -632,6 +647,9 @@ const DefaultController = {
632647 if ( options . tags && Object . keys ( options . tags ) . length > 0 ) {
633648 headers [ 'X-Parse-File-Tags' ] = JSON . stringify ( options . tags ) ;
634649 }
650+ if ( options . maxUploadSize ) {
651+ headers [ 'X-Parse-File-Max-Upload-Size' ] = options . maxUploadSize . replace ( / [ \r \n ] / g, '' ) ;
652+ }
635653 const jsKey = CoreManager . get ( 'JAVASCRIPT_KEY' ) ;
636654 if ( jsKey ) {
637655 headers [ 'X-Parse-JavaScript-Key' ] = jsKey ;
0 commit comments