Answers.Body: <p>As you discovered, the way to go about this is with AssetsService::insertFileByLocalPath().</p>
  
  <p>Not sure about the error you’re getting though. If you haven’t had any luck figuring that out, send your plugin over to support@buildwithcraft.com with instructions on how to reproduce, and we can look into it.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-21T00:02:47.730Z
Answers.LastActivityDate: 2014-10-21T00:02:47.730Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I have a plugin and I want it to move some files into a system asset source.  </p>
  
  <p>I have a dropdown to select the folder which gets its options like this and shows a dropdown to select a folder Id.</p>
  
  <pre><code>public function getSettingsHtml()
  {
        $sourceIds = craft()-&gt;assetSources-&gt;getAllSourceIds();
        $tree = craft()-&gt;assets-&gt;getFolderTreeBySourceIds($sourceIds);
  
        return craft()-&gt;templates-&gt;render('backups/_settings', array(
            'settings' =&gt; $this-&gt;getSettings(),
            'tree' =&gt; $tree
        ));
  }
  </code></pre>
  
  <p>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?</p>
  
  <p>Any thoughts?</p>
  
  <p><em>UPDATE</em>: So I found this method in the Assets Service <code>insertFileByLocalPath()</code> which seems exactly what i needed</p>
  
  <pre><code>$response = craft()-&gt;assets-&gt;insertFileByLocalPath($backupsPath, $fileName, $folderId);
  </code></pre>
  
  <p>which starts to work but i keep getting <code>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.</code>??</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-07-05T16:22:44.270Z
Comments.Text: Same thing with my code. Did you find a solution for that S3 RequestTimeout?
Comments.UserDisplayName: Karsten Schempp
Tags: <assets><plugins>
Title: Can plugin copy file into an asset source?
ThreadText: # Can plugin copy file into an asset source?
  
  (Asked by: username_0 on 2014-10-18)
  
  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.`??
  
  **Tags:** assets, plugins
  
  > **Comments:**
  > **username_1**: Same thing with my code. Did you find a solution for that S3 RequestTimeout?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2014-10-21. Score: 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 support@buildwithcraft.com with instructions on how to reproduce, and we can look into it.
  
  
  ---
  
  