I have a plugin and I want it to move some files into a system asset source.

I have a dropdown to select the folder which gets its options like this and shows a dropdown to select a folder Id.

public function getSettingsHtml()
      $sourceIds = craft()->assetSources->getAllSourceIds();
      $tree = craft()->assets->getFolderTreeBySourceIds($sourceIds);

      return craft()->templates->render('backups/_settings', array(
          'settings' => $this->getSettings(),
          'tree' => $tree

so in my controller what i want to do is copy a file into that folder? I have the full path to the file but not sure where to go from there? Ideally it wouldn't matter if it were local storage or cloud storage it would just move it but I'm a little dumbfounded?

Any thoughts?

UPDATE: So I found this method in the Assets Service insertFileByLocalPath() which seems exactly what i needed

$response = craft()->assets->insertFileByLocalPath($backupsPath, $fileName, $folderId);

which starts to work but i keep getting S3::putObject(): [RequestTimeout] Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed.??

  • Same thing with my code. Did you find a solution for that S3 RequestTimeout? Jul 5, 2018 at 16:22

1 Answer 1


As you discovered, the way to go about this is with AssetsService::insertFileByLocalPath().

Not sure about the error you’re getting though. If you haven’t had any luck figuring that out, send your plugin over to [email protected] with instructions on how to reproduce, and we can look into it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.