diff --git a/frontend/js/components/media-library/Uploader.vue b/frontend/js/components/media-library/Uploader.vue index 28fbfbcca..3a7ae6b4e 100644 --- a/frontend/js/components/media-library/Uploader.vue +++ b/frontend/js/components/media-library/Uploader.vue @@ -197,46 +197,53 @@ this.uploadProgress(0) }, _onSubmitCallback (id, name) { - this.$emit('clear') - // each upload session will add upload files with original filenames in a folder named using a uuid - this.unique_folder_name = this.unique_folder_name || (this.uploaderConfig.endpointRoot + qq.getUniqueId()) - this._uploader.methods.setParams({ - unique_folder_name: this.unique_folder_name, - media_to_replace_id: this.media_to_replace_id - }, id) + return new Promise((resolve, reject) => { + // halt fine uploader upload until image is loaded + // so we can send image dimensions with the upload + const img = new Image() + img.onload = () => { + this.$emit('clear') + // each upload session will add upload files with original filenames in a folder named using a uuid + this.unique_folder_name = this.unique_folder_name || (this.uploaderConfig.endpointRoot + qq.getUniqueId()) - // determine the image dimensions and add it to params sent on upload success - const imageUrl = URL.createObjectURL(this._uploader.methods.getFile(id)) - const img = new Image() + // determine the image dimensions and add it to params sent on upload success + this._uploader.methods.setParams({ + width: img.width, + height: img.height, + unique_folder_name: this.unique_folder_name, + media_to_replace_id: this.media_to_replace_id + }, id) - img.onload = () => { - this._uploader.methods.setParams({ - width: img.width, - height: img.height, - unique_folder_name: this.unique_folder_name, - media_to_replace_id: this.media_to_replace_id - }, id) - this.media_to_replace_id = null - } + this.media_to_replace_id = null - img.src = imageUrl + const media = { + id: this._uploader.methods.getUuid(id), + name: sanitizeFilename(name), + progress: 0, + error: false, + errorMessage: null, + isReplacement: !!this.media_to_replace_id, + replacementId: this.media_to_replace_id + } - const media = { - id: this._uploader.methods.getUuid(id), - name: sanitizeFilename(name), - progress: 0, - error: false, - errorMessage: null, - isReplacement: !!this.media_to_replace_id, - replacementId: this.media_to_replace_id - } + if (this.type.value === 'file') { + this.media_to_replace_id = null + } - if (this.type.value === 'file') { - this.media_to_replace_id = null - } + this.loadingMedias.push(media) + this.loadingProgress(media) + + // resolve the promise, allow the upload to continue + resolve(img) + } + + img.onerror = (err) => { + console.error(err) // eslint-disable-line + reject(err); + } - this.loadingMedias.push(media) - this.loadingProgress(media) + img.src = URL.createObjectURL(this._uploader.methods.getFile(id)) + }); }, _onProgressCallback (id, name, uploadedBytes, totalBytes) { const index = this.loadingMedias.findIndex((m) => m.id === this._uploader.methods.getUuid(id)) diff --git a/src/Http/Controllers/Admin/MediaLibraryController.php b/src/Http/Controllers/Admin/MediaLibraryController.php index 6b11e2b75..bbe69e0e2 100644 --- a/src/Http/Controllers/Admin/MediaLibraryController.php +++ b/src/Http/Controllers/Admin/MediaLibraryController.php @@ -185,7 +185,12 @@ public function storeFile($request) $uploadedFile = $request->file('qqfile'); - [$w, $h] = getimagesize($uploadedFile->path()); + if ($request->input('width') && $request->input('height')) { + $w = $request->input('width'); + $h = $request->input('height'); + } else { + [$w, $h] = getimagesize($uploadedFile->path()); + } $uploadedFile->storeAs($fileDirectory, $filename, $disk);