startFileDataUpload method

Future<Response<FileUploadURL>> startFileDataUpload({
  1. required String fileId,
  2. required int versionId,
  3. required String fileType,
  4. @Deprecated('partNumber is deprecated') int? partNumber,
  5. CancelToken? cancelToken,
  6. Map<String, dynamic>? headers,
  7. Map<String, dynamic>? extra,
  8. ValidateStatus? validateStatus,
  9. ProgressCallback? onSendProgress,
  10. ProgressCallback? onReceiveProgress,
})

Start FileData Upload Starts an upload of a specific FilePart. This endpoint will return an AWS URL which you can PUT data to. You need to call this and receive a new AWS API URL for each `partNumber`. Please see AWS's REST documentation on &quot;PUT Object to S3&quot; on how to upload. Once all parts has been uploaded, proceed to `/finish` endpoint. Note: `nextPartNumber` seems like it is always ignored. Despite it returning 0, first partNumber is always 1.

Parameters:

  • fileId - Must be a valid file ID.
  • versionId - Version ID of the asset.
  • fileType - Type of file.
  • partNumber - The part number to start uploading. If not provided, the first part will be started.
  • cancelToken - A CancelToken that can be used to cancel the operation
  • headers - Can be used to add additional headers to the request
  • extras - Can be used to add flags to the request
  • validateStatus - A ValidateStatus callback that can be used to determine request success based on the HTTP status of the response
  • onSendProgress - A ProgressCallback that can be used to get the send progress
  • onReceiveProgress - A ProgressCallback that can be used to get the receive progress

Returns a Future containing a Response with a FileUploadURL as data Throws DioException if API call or serialization fails

Implementation

Future<Response<FileUploadURL>> startFileDataUpload({
  required String fileId,
  required int versionId,
  required String fileType,
  @Deprecated('partNumber is deprecated') int? partNumber,
  CancelToken? cancelToken,
  Map<String, dynamic>? headers,
  Map<String, dynamic>? extra,
  ValidateStatus? validateStatus,
  ProgressCallback? onSendProgress,
  ProgressCallback? onReceiveProgress,
}) async {
  final _path = r'/file/{fileId}/{versionId}/{fileType}/start'
      .replaceAll('{' r'fileId' '}', fileId.toString())
      .replaceAll('{' r'versionId' '}', versionId.toString())
      .replaceAll('{' r'fileType' '}', fileType.toString());
  final _options = Options(
    method: r'PUT',
    headers: <String, dynamic>{
      ...?headers,
    },
    extra: <String, dynamic>{
      'secure': <Map<String, String>>[
        {
          'type': 'apiKey',
          'name': 'authCookie',
          'keyName': 'auth',
          'where': '',
        },
      ],
      ...?extra,
    },
    validateStatus: validateStatus,
  );

  final _queryParameters = <String, dynamic>{
    if (partNumber != null) r'partNumber': partNumber,
  };

  final _response = await _dio.request<Object>(
    _path,
    options: _options,
    queryParameters: _queryParameters,
    cancelToken: cancelToken,
    onSendProgress: onSendProgress,
    onReceiveProgress: onReceiveProgress,
  );

  FileUploadURL? _responseData;

  try {
    final rawData = _response.data;
    _responseData = rawData == null
        ? null
        : deserialize<FileUploadURL, FileUploadURL>(rawData, 'FileUploadURL',
            growable: true);
  } catch (error, stackTrace) {
    throw DioException(
      requestOptions: _response.requestOptions,
      response: _response,
      type: DioExceptionType.unknown,
      error: error,
      stackTrace: stackTrace,
    );
  }

  return Response<FileUploadURL>(
    data: _responseData,
    headers: _response.headers,
    isRedirect: _response.isRedirect,
    requestOptions: _response.requestOptions,
    redirects: _response.redirects,
    statusCode: _response.statusCode,
    statusMessage: _response.statusMessage,
    extra: _response.extra,
  );
}