Status Polling for a pdf file stored on remote server

Community Beginner ,
Jul 18, 2022 Jul 18, 2022

Copy link to clipboard

Copied

From the adobe react repo on GitHub, inside the saveApiHandler, I am calling a server api to store and save the document. The functionality works fine, as I am able to save the document.

Now I want to implement the overwriting feature using Status Callback. The documentation tells to use the save and status callback together but did not elaborate further on the topic as How.  Please advise about the following.

1. My documents are stored on the server, saved and retrieved through rest calls. How can the status api detect the changes on the server if made by another user.

 

2.  How can I use the save and status callbacks together to achieve the complete save experience (as stated in the documentation). Both are separate callbacks and executes at a different time in the application life cycle.

 

3. Is there simple documentation on how to handle this very common scenario of preventing overwriting files are when saved through rest calls?

 

 

Here is my code for save api handler

registerSaveApiHandler() {
  const saveApiHandler = (metaData, content, options) => {
			return new Promise(function (resolve, reject) {
				fetch('http://localhost:4000/api/save', {
					method: 'POST',
					body: formData
				}).then((response) => {
					if (response.status === 200) {
						const pdfResponse = {
							code: window.AdobeDC.View.Enum.ApiResponseCode.SUCCESS,
							data: {
								metaData: Object.assign(metaData, { updatedAt: new Date().getTime() })
							},
						};
						resolve(pdfResponse);

					} else {
						const pdfResponse = {
							code: window.AdobeDC.View.Enum.ApiResponseCode.FAIL,
							data: {
								metaData: Object.assign(metaData, { updatedAt: new Date().getTime() })
							},
						};
						reject(pdfResponse);
						window.location.reload();
					}
				}).catch(e => {
					const pdfResponse = {
						code: window.AdobeDC.View.Enum.ApiResponseCode.FAIL,
						data: {
							metaData: Object.assign(metaData, { updatedAt: new Date().getTime() })
						},
					};
					reject(pdfResponse);
				});
			});
		};

		this.adobeDCView.registerCallback(
			window.AdobeDC.View.Enum.CallbackType.SAVE_API,
			saveApiHandler,
			{}
		);
	}

 

Any guidance is highly appreciated.

Views

38

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation
Resources