Skip to content

Improve error reporting for products images import #4711

Closed
@leoquijano

Description

@leoquijano

When importing products using the System -> Import Products feature, if there problems importing the images, Magento just fails with:

1. Imported resource (image) could not be downloaded from external resource due to timeout or access permissions in rows: ...

No information is given about the cause of the problem, nor any help for the developer to sort it out. Generic calls to fix permissions don't really help, and it makes the process of importing products way longer than expected.

As explained here, exception handling could be improved to provide helpful messages to the developer. In particular, the following can be added to vendor/magento/module-catalog-import-export/Model/Import/Product.php:

protected function uploadMediaFiles($fileName, $renameFileOff = false)
{
    try {
        $res = $this->_getUploader()->move($fileName, $renameFileOff);
        return $res['file'];
    } catch (\Exception $e) {
        return '';
    }
}

Swallowing exceptions is a very bad thing, so it'd be a good idea to improve it like this:

protected function uploadMediaFiles($fileName, $renameFileOff = false)
{
    try {
        $res = $this->_getUploader()->move($fileName, $renameFileOff);
        return $res['file'];
    } catch (\Exception $e) {
        $this->_logger->critical($e);
        return '';
    }
}

Metadata

Metadata

Assignees

Labels

Component: ImportExportFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is not validGate 1 Failed. Automatic verification of issue format is failedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releasebug report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions