Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add images without backend #238

Open
kan-ish opened this issue Jan 22, 2024 · 0 comments
Open

Add images without backend #238

kan-ish opened this issue Jan 22, 2024 · 0 comments

Comments

@kan-ish
Copy link

kan-ish commented Jan 22, 2024

The library should have a method for uploading images without sending the images to a backend, should the user need it. I have implemented a solution to this with the following code for the uploadByFile function provided by the libary -

async uploadByFile(file) {
	const response = await uploadFile(file);
	if (response.success) {
		return {
			success: 1,
			file: {
				url: response.file,
			},
		};
	}
}

async function uploadFile(file) {
	return new Promise((resolve, reject) => {
		const reader = new FileReader();
		reader.onload = function (e) {
			const base64URL = e.target.result;
			resolve({ success: 1, file: base64URL });
		};

		reader.onerror = function (error) {
			reject(error);
		};

		reader.readAsDataURL(file);
	});
}

The user can then store the saved editor data (obtained from editor.save()) as-it-is in the backend as an object or even a single string, without the images being stored elsewhere. Some users might need this, as did I.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant