How to custom AttachmentHandler in FE

Hi, I’m working with the AttachmentHandler on the front-end side and now I want to send a few properties together with the file so that the BE can work based on that property.

Dive deeper into the code I see that in the AttachmentHeader we have a property called “annotations” which may be helpful for us. How can I use that “annotations” in the AttachmentHandler or what is the best way to custom it in this situation?

Thank you

Hi @vinh-neural-shore, so with your case:

  • Deep dive into the attachment handler of Client, I realize that the request does not include annotation params for sending to server.
  • So if you want to achieve your case, I suggest that you provide your own custom attachment handler in client side to pass annotation in url then BE can handle it.

Code example ( Just for reference):

file
		.arrayBuffer()
		.then(bufferContent => {
			logger.log(`Uploading the attachment "${file.name}" is started.`);
			const annotationsParameter = ` Your annotations value `

			const request = AttachmentUploadV2.Request.build({
				fileName: file.name,
				documentModelName,
				content: bufferContent,
				pathToField: attachmentPath
			});

			return RestRequestDispatcher.json(
				{
					...request,
					relativeUrl: `${request.relativeUrl}${annotationsParameter ? `&annotations=${annotationsParameter}` : ""}`,
					signal: abortController.signal
				},
				AttachmentHeader.isInstance
			);
		})
		.then(result => {
			logger.log(`Uploading the attachment "${file.name}" is done.`);
			handleOnDone(result, attachment, handler);
		})
		.catch(reason => {
			handleErrorResponse(reason, handler.onError);
		}); 

Thanks Long, I applied your answer and it worked