-/**
- * Upload an image file to the server
- * @param {File} file
- * @param {int} pageId
- */
-async function uploadImageFile(file, pageId) {
- if (file === null || file.type.indexOf('image') !== 0) {
- throw new Error(`Not an image file`);
- }
-
- let ext = 'png';
- if (file.name) {
- let fileNameMatches = file.name.match(/\.(.+)$/);
- if (fileNameMatches.length > 1) ext = fileNameMatches[1];
- }
-
- const remoteFilename = "image-" + Date.now() + "." + ext;
- const formData = new FormData();
- formData.append('file', file, remoteFilename);
- formData.append('uploaded_to', pageId);
-
- const resp = await window.$http.post(window.baseUrl('/images/gallery'), formData);
- return resp.data;
-}
-