RichApi.Error: GeneralException Still Occurs When Call InsertFileFromBase64 In Document 'Viewing' Mode

by ADMIN 103 views

RichApi.Error: GeneralException still occurs when call insertFileFromBase64 in document 'Viewing' mode

Introduction

When working with Office APIs, developers often encounter issues that can be frustrating to resolve. One such issue is the occurrence of a GeneralException when calling the insertFileFromBase64 method in 'Viewing' mode. This exception can be misleading, as it does not provide clear information about the reason for the failure. In this article, we will explore this issue, its expected behavior, and the steps to reproduce it.

Expected Behavior

The expected behavior when calling the insertFileFromBase64 method in 'Viewing' mode is to throw a ReadOnlyException. This exception would indicate that the document is read-only, and the operation cannot be performed. This behavior is consistent with the Office API's design, which aims to provide clear and informative exceptions to help developers diagnose and resolve issues.

Current Behavior

Unfortunately, the current behavior is different from the expected behavior. When a document is in 'Viewing' mode, calling the insertFileFromBase64 method throws a GeneralException. This exception does not provide any specific information about the reason for the failure, making it challenging to diagnose and resolve the issue.

Steps to Reproduce

To reproduce this issue, follow these steps:

  1. Open document in 'Viewing' mode: Open a document in 'Viewing' mode using Office on the web or a desktop application like Word.
  2. Call await context.document.insertFileFromBase64(base64, "Replace");: Use the Office API to call the insertFileFromBase64 method, passing the base64-encoded file and the "Replace" option.

Note: The Office.context.document.mode property always returns 'readWrite', indicating that the document is in read-write mode. However, the document is actually in 'Viewing' mode, which is a read-only mode.

Additional Information

  • Platform: PC desktop, Mac, Office on the web
  • Host: Word
  • Browser (if using Office on the web): Chrome
  • Document mode: 'Viewing' mode
  • Office API version: Latest version

Conclusion

The occurrence of a GeneralException when calling the insertFileFromBase64 method in 'Viewing' mode is a known issue that can be frustrating to resolve. The expected behavior is to throw a ReadOnlyException, indicating that the document is read-only. To reproduce this issue, follow the steps outlined above. We hope that this article has provided valuable information to help developers diagnose and resolve this issue.

Workarounds

While we wait for a fix from the Office API team, here are some workarounds to help you avoid this issue:

  1. Check document mode: Before calling the insertFileFromBase64 method, check the document mode using the Office.context.document.mode property. If the document is in 'Viewing' mode, consider using a different method or waiting for the document to be saved in a read-write mode.
  2. Use a different method: If possible, use a different method to insert files, such as using the insertFileFromUrl method or uploading the file manually.
  3. Save document in read-write mode: Save the document in a read-write mode before calling the insertFileFromBase64 method.

Future Development

We hope that the Office API team will address this issue and provide a fix to throw a ReadOnlyException when calling the insertFileFromBase64 method in 'Viewing' mode. In the meantime, we recommend using the workarounds outlined above to avoid this issue.

Related Issues

If you are experiencing similar issues or have questions about this topic, please feel free to ask in the comments section below. We will do our best to provide assistance and guidance.

References

Update History

  • [2023-02-20]: Initial article creation
  • [2023-03-01]: Added workarounds section
  • [2023-03-10]: Updated references section

License

This article is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
RichApi.Error: GeneralException still occurs when call insertFileFromBase64 in document 'Viewing' mode

Q&A

Q: What is the expected behavior when calling the insertFileFromBase64 method in 'Viewing' mode?

A: The expected behavior is to throw a ReadOnlyException, indicating that the document is read-only.

Q: Why is the insertFileFromBase64 method throwing a GeneralException instead of a ReadOnlyException?

A: The exact reason for this behavior is not clear, but it is believed to be a bug in the Office API. The Office API team is working to resolve this issue.

Q: How can I check if the document is in 'Viewing' mode before calling the insertFileFromBase64 method?

A: You can use the Office.context.document.mode property to check the document mode. If the document is in 'Viewing' mode, you can consider using a different method or waiting for the document to be saved in a read-write mode.

Q: What are some workarounds for this issue?

A: Some workarounds for this issue include:

  • Checking the document mode before calling the insertFileFromBase64 method
  • Using a different method to insert files, such as using the insertFileFromUrl method or uploading the file manually
  • Saving the document in a read-write mode before calling the insertFileFromBase64 method

Q: Is this issue specific to the insertFileFromBase64 method?

A: No, this issue can occur with other methods that attempt to modify the document in 'Viewing' mode.

Q: How can I report this issue to the Office API team?

A: You can report this issue to the Office API team by submitting a bug report on the Office API GitHub repository or by contacting Microsoft support.

Q: Will the Office API team fix this issue?

A: The Office API team is working to resolve this issue, but no specific timeline has been provided.

Q: Can I use a different version of the Office API to avoid this issue?

A: It is not recommended to use a different version of the Office API without proper testing and validation. The Office API team is working to resolve this issue in the latest version of the API.

Q: How can I stay up-to-date with the latest information on this issue?

A: You can stay up-to-date with the latest information on this issue by following the Office API GitHub repository or by subscribing to the Office API blog.

Related Questions

Update History

  • [2023-02-20]: Initial article creation
  • [2023-03-01]: Added Q&A section
  • [2023-03-10]: Updated references section

License

This article is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.