Creating and Uploading an Asset
GraphQL flow chart:
1. Creating the Asset Entity
Replace [FOLDER_ID]
and [FILE_NAME]
in order to create an asset entity.
mutation {
createAssetV3(params: { folderId: "[FOLDER_ID]", name: "[FILE_NAME]" })
... on GroupedAssetOutput {
id
}
}
Attach the bearer token to the graphql headers:
{
"authorization": "Bearer eyJraWQiOiJydGdqUUxXZTBqbExIWHVBUm8zR1lP….."
}
Response:
{
"data": {
"createAssetV3": {
"id": "f5fa9a0d-7479-49bf-8962-4fab70b89de9"
}
}
}
2. Creating a File
Replace [GROUPED_ASSET_ID]
(e.g. "f5fa9a0d-7479-49bf-8962-4fab70b89de9" from the first step), [FILE_NAME]
and [FILE_SIZE]
to create a file entity, by using the ID from the GroupedAssetOutput.
Repeat this process for every file associated with a single asset.
mutation {
addFileV2(params: { groupedAssetId: "[GROUPED_ASSET_ID]", fileName: "[FILE_NAME]", fileSize: [FILE_SIZE] }) {
... on FileOutput {
id
}
}
}
Response:
{
"data": {
"addFileV2": {
"id": "3126a9ae-9ae0-498b-83c1-524249b523f3"
}
}
}
3. Generating a Presigned URL for the File
Split the file into parts and replace the [PART_NUMBER]
and [FILE_ID]
(e.g.
"3126a9ae-9ae0-498b-83c1-524249b523f3" from the previous step) to generate a presigned url to upload the file in parts. Repeat this step for all parts.
query {
multipartUploadURL(params: { partNumber: [PART_NUMBER], fileId: "[FILE_ID]" }) {
... on MultipartUploadUrlOutput {
uploadUrl
}
}
}
Response:
{
"data": {
"getMultipartUploadURL": {
"uploadUrl": "https://s3.[AWS_REGION].amazonaws.com/[HXDR_ENVIRONMENT]/assets/[ASSET_ID]/[FILE_NAME]?uploadId=[UPLOAD_ID]&partNumber=[PART_NUMBER]&X-Amz-Security-Token=[SECURITY_TOKEN]&X-Amz-Algorithm=[ALGORITHM]&X-Amz-Date=[DATE]&X-Amz-SignedHeaders=[SIGNED_HEADERS]&X-Amz-Expires=[EXPIRATION]&X-Amz-Credential=[CREDENTIALS]&X-Amz-Signature=[SIGNATURE]"
}
}
}
Note: Nothing has to be replaced in this response. It has been shortend to hide any real data.
The uploadUrl
is the place to PUT
the part. This is a direct connection to AWS S3 (opens in a new tab). The etag
is located in the header of a successful response of an uploaded part which is needed for the next step.
To upload the data via the presigned url via a terminal, the following command can be used
curl --request PUT --url "[UPLOAD_URL]" --verbose --upload-file example.file .
4. Completing a File
In order to complete a file, replace [PART_NUMBER]
, [ETAG]
and [LIST_OF_PART_OBJECTS]
. Repeat this step for every file (not part!) that has been uploaded.
mutation {
completeMultipartUpload(
params: {
fileId: "[FILE_ID]",
multipartUploadsETags: [LIST_OF_PART_OBJECTS]
}
) {
... on ExecutedOutput{
executed
}
}
Where [LIST_OF_PART_OBJECTS] each object has the below fields:
{
part: [PART_NUMBER],
etag: "[ETAG]"
}
Example:
mutation {
completeMultipartUpload(
params: {
fileId: "3126a9ae-9ae0-498b-83c1-524249b523f3",
multipartUploadsETags: [{
part: 1,
etag: "etag_1"
},
...,
{
part: n,
etag: "etag_n"
}]
}
) {
executed
}
}
Response:
{
"data": {
"completeMultipartUpload": {
"executed": true
}
}
}
5. Completing an Asset
Replace [GROUPED_ASSET_ID]
with the ID from step 1. After all files have been uploaded and completed, the asset can be processed. This will happen when triggering completeAssetFileList
.
mutation {
completeAssetFileList(groupedAssetId: { assetId: "[GROUPED_ASSET_ID]" }) {
... on ExecutedOutput {
executed
message
}
}
}
Response:
{
"data": {
"completeAssetFileList": {
"executed": true,
"message": "Asset Upload is completed"
}
}
}
Once all of the above steps have been completed, the automatic triggering of a specific pipeline will happen. The type of pipeline triggered depends on the assetType uploaded or the file extension of the uploaded file.
JS-SDK reference
Assets
HxDR Assets