Import file programmatically into Curator database #237
-
Hi, I am creating a Command to process a batch import from a WordPress, and I would like to add all attachments to the Curator Media Library. I can download the file from the external URL in a temporary file and convert it to a class UrlUploadedFile extends UploadedFile
{
public static function createFromUrl(string $url, string $originalName = '', string $mimeType = null, int $error = null, bool $test = false): self
{
if (! $stream = @fopen($url, 'r')) {
throw new CantOpenFileFromUrlException($url);
}
$tempFile = tempnam(sys_get_temp_dir(), 'url-file-');
file_put_contents($tempFile, $stream);
return new static($tempFile, $originalName, $mimeType, $error, $test);
}
} But I would like to import it to the "media" table (using Curator Storage configuration, same upload like using the Curator Resource in the back-office), so the file can shows up on the Resource page of the Filament back-office. Is there a way to do import/upload a file (image) programmatically using the "Curator way" ? Thanks in advance, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
At the console level there's not really a "curator way" or even filament way. But I am doing the same thing. I can't share that repo but I can put something together for you to show you what I'm doing to migrate the media first then posts etc to attach the records to the posts. Give me an hour or two. |
Beta Was this translation helpful? Give feedback.
-
A lot of this might not apply to your set up, but hopefully can give you some insight. https://gist.github.com/awcodes/982873d502ed2ee7903c2f68a33623c5 |
Beta Was this translation helpful? Give feedback.
-
Oh very cool ! I am going to do a form in front-end (users that can change their avatar) and I will use the same way to add these files to Curator. Thank you very much ! |
Beta Was this translation helpful? Give feedback.
A lot of this might not apply to your set up, but hopefully can give you some insight.
https://gist.github.com/awcodes/982873d502ed2ee7903c2f68a33623c5