I am currently in the process of migrating an old SMF Forum to Flarum - with fof-upload enabled. Is there a way to upload old SMF-Attachments via API to Flarum in this migration process?
I managed to solve this for User-Avatars (see below) but i am somewhat at a loss to solve this for attachments to a post in Flarum. As Flarum needs fof-upload to upload images to posts, i guessed it had to be done via the plugins upload URL /api/fof/upload
. Looking at the network traffic from /api/fof/upload
it seems, that the only thing sent with the POST-request is the image itself, but no User-ID, filename or such things. And at least the User-ID might be necessary to populate actor_id
in the table fof_upload_files
correctly.
Maybe somebody can point me in the right direction...
// Avatar Migration
$avatar = array();
$avatar = $smf->query('SELECT * FROM `smf_attachments` WHERE ID_MEMBER = '.$userId)->fetchAll();
// Buggy Avatar Picture for SMF user with id 739
if (count($avatar) > 0 && $userId != 739) {
// echo $userId."\n";
// var_dump($avatar);
$avatarUrl = smf_url."index.php?action=dlattach;attach=".$avatar[0]['ID_ATTACH'].";type=avatar";
if (file_put_contents('/tmp/avatarmigration', fopen($avatarUrl, 'r'))) {
$response = $api->request(
'POST',
'users/' . $userId . '/avatar',
[
'multipart' => [
[
'name' => 'avatar',
'contents' => fopen('/tmp/avatarmigration', 'r'),
'filename' => 'avatar-migrated-from-smf.png'
]
]
]
);
// var_dump(json_decode($response->getBody(), true));
}
}