Menu Close
    Start a Project Request quote Reading list Switch to dark mode
    marketplace-mod

    How to upload media through URL in Shopware6

    Overview

    In this article we learn about how to upload media through URL in Shopware6.

    Media Upload Method

    Collect the Media URL in an array and create a media repository. We need to add to services FileFetcher and FileSaver , if you are in custom service then also register   ContinerInterface.

    We recommended the following  processor

    In the above code we create a service for image upload, first of all we need to register our service into seervice.xml file for access globally. then pass argument into service, find below service.xml code..

    passing service container, FileFetcher and FileSaver predefined services into our custom service. first of all define these service into class service constructor function for further use in our function.then create a function for upload media URL for Shopware6. Create default context object then create media repository from container. After this get extension of URL by this code pathinfo($url, PATHINFO_EXTENSION), then get filename from this method basename($url, $ext). Further create request object through URL and extension by this way new Request([‘extension’ => $ext], [‘url’ => $url]); and get tempFile of the image from this method tempnam(sys_get_temp_dir(), ”);

    Through FileFetcher we can get the file object of URL passing request and tempFile.

    I hope it will help you. Thanks for reading 🙂

    . . .

    Comment

    Add Your Comment

    Be the first to comment.

    Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close