Skip to content

Commit 0ea8141

Browse files
authored
Merge pull request #173 from IQSS/163-improve-file-upload-use-case
Enhanced File Uploading
2 parents 69f4005 + 9ec52b5 commit 0ea8141

File tree

14 files changed

+932
-353
lines changed

14 files changed

+932
-353
lines changed

docs/useCases.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ getDatasetFiles
873873
These use cases are designed to facilitate the uploading of files to a remote S3 storage and subsequently adding them to a dataset. This process involves two main steps / use cases:
874874

875875
1. Uploading a file to remote S3 storage and obtaining a storage identifier.
876-
2. Adding the uploaded file to the dataset using the obtained storage identifier.
876+
2. Adding one or more uploaded files to the dataset using the obtained storage identifiers.
877877

878878
This use case flow is entirely based on the Direct Upload API as described in the Dataverse documentation: https://guides.dataverse.org/en/latest/developers/s3-direct-upload-api.html
879879

@@ -910,35 +910,41 @@ The `progress` parameter represents a callback function that allows the caller t
910910

911911
The `abortController` is a built-in mechanism in modern web browsers that allows the cancellation of asynchronous operations. It works in conjunction with an associated AbortSignal, which will be passed to the file uploading API calls to monitor whether the operation should be aborted, if the caller decides to cancel the operation midway.
912912

913-
##### Add Uploaded File to the Dataset
913+
##### Add Uploaded Files to the Dataset
914914

915-
This use case involves adding a file that has been previously uploaded to remote storage to the dataset.
915+
This use case involves adding files that have been previously uploaded to remote storage to the dataset.
916916

917917
###### Example call:
918918

919919
```typescript
920-
import { addUploadedFileToDataset } from '@iqss/dataverse-client-javascript'
920+
import { addUploadedFilesToDataset } from '@iqss/dataverse-client-javascript'
921+
import { UploadedFileDTO } from '@iqss/dataverse-client-javascript'
921922

922923
/* ... */
923924

924925
const datasetId: number | string = 123
925-
const file: File = new File(['content'], 'example.txt', { type: 'text/plain' })
926-
const storageId: string = 'some-storage-identifier'
927-
928-
addUploadedFileToDataset.execute(datasetId, file, storageId).then(() => {
929-
console.log('File added to the dataset successfully.')
926+
const uploadedFileDTOs: UploadedFileDTO[] = [
927+
{
928+
fileName: 'the-file-name',
929+
storageId: 'localstack1://mybucket:19121faf7e7-2c40322ff54e',
930+
checksumType: 'md5',
931+
checksumValue: 'ede3d3b685b4e137ba4cb2521329a75e',
932+
mimeType: 'text/plain'
933+
}
934+
]
935+
936+
addUploadedFilesToDataset.execute(datasetId, uploadedFileDTOs).then(() => {
937+
console.log('Files added to the dataset successfully.')
930938
})
931939

932940
/* ... */
933941
```
934942

935-
_See [use case](../src/files/domain/useCases/AddUploadedFileToDataset.ts) implementation_.
943+
_See [use case](../src/files/domain/useCases/AddUploadedFilesToDataset.ts) implementation_.
936944

937945
The `datasetId` parameter can be a string, for persistent identifiers, or a number, for numeric identifiers.
938946

939-
The `file` parameter is a subclass of Blob (Binary Large Object) that represents a file.
940-
941-
The `storageId` parameter represents the storage identifier obtained after a successful call to the UploadFile use case.
947+
The `uploadedFileDTOs` parameter is an array of [UploadedFileDTO](../src/files/domain/dtos/UploadedFileDTO.ts) and includes properties related to the uploaded files. Some of these properties should be calculated from the uploaded File Blob objects and the resulting storage identifiers from the Upload File use case.
942948

943949
##### Error handling:
944950

0 commit comments

Comments
 (0)