I’m looking into a way to use this approach in the outdated strapi-plugin-import-content plugin that I’m trying to fix. I just don’t feel comfortable calling this method IN BULK, let’s say in batches of 50: this will download 50 images at once, create 50 FormData objects containing the binary data of these images and do 50 POST requests to the content-manager endpoints…
thanks for the mention! I think I found a possible root cause for both the async image import and the upload from url feature not working. It seems the Strapi upload service, allthough documented to handle both files and Buffers, can only handle files since it expects a path attribute to exist on the uploaded file.
When working with Buffers however, there is no file path as the file is not created and only exists as Buffer in memory. By simply adding a check if the path attribute exists, I could work around this and effectively upload images to the media library, even without user info (as long as I make the media / upload endpoint publicly accessible).
sadly enough the change above DOES NOT fix the Media library “from URL” feature.
I’m still working on my own version of the import-content plugin, published here: GitHub - kiddicolour/strapi-plugin-import-content as all I have left to do is fix a weird bug.
When sending the related file data to the upload service, it somehow is not handled correctly. The upload_file_morph record is correctly created in the database, but somehow it references the url of the file instead of the id, allthough passed in correctly as numeric value. As soon as I manually adjust the value in the database to point to an actual id instead of the string url, the media is correctly linked and displayed. I also want to add a content type override option, as the images that I need to import are hosted on an old wordpress server that doesn’t pass the correct Content-Type (each png images gets Content-Type “text/html”. Other servers I’ve tested with, send the correct mimetype…
Has anyone successfuly implemented this? Trying to get it done in v4, to seed my strapi db from another CMS, with no luck so far. I had an implementation for v3 where I downloaded the files to my fs then uploaded them and it worked, would be nice to skip the writting to system part…
Here is my blob implementation, heavily inspired from above. after raising the file size limits in the middleware.js file. I’m still getting a 400 error “files are empty”
After a bit of trial and error, I got this working in V4! My use case is that I fetch the profile image of users who authenticate via third party provider, and then upload that image to my Strapi / S3 bucket.
Here is my implementation. I’m using a beforeCreate lifecycle function in src/extensions/users-permissions/content-types/user/lifecycles.js