<p>You can move them like this</p>

<pre class="lang-PHP prettyprint-override"><code>$asset = Asset::find()-&gt;volume('resourceImages')-&gt;filename($filename)-&gt;one()
$folder = Craft::$app-&gt;getAssets()-&gt;findFolder(['volumeId' =&gt; X]);
Craft::$app-&gt;getAssets()-&gt;moveAsset($asset, $folder, $filename);
</code></pre>

<p>It won't change your relations or anything else in fact all the function does is:</p>

<pre class="lang-PHP prettyprint-override"><code>/**
 * Move or rename an Asset.
 *
 * @param Asset $asset The asset whose file should be renamed
 * @param VolumeFolder $folder The Volume Folder to move the Asset to.
 * @param string $filename The new filename
 * @return bool Whether the asset was renamed successfully
 * @throws AssetLogicException if the asset’s volume is missing
 */
public function moveAsset(Asset $asset, VolumeFolder $folder, string $filename = ''): bool
{
    // Set the new combined target location, and save it
    $asset-&gt;newFilename = $filename;
    $asset-&gt;newFolderId = $folder-&gt;id;
    $asset-&gt;setScenario(Asset::SCENARIO_FILEOPS);

    return Craft::$app-&gt;getElements()-&gt;saveElement($asset);
}
</code></pre>

CC BY-SA 4.0
2018-10-08T20:11:31.937Z
2018-10-08T20:11:31.937Z
Robin Schambach
<p>Im trying to figure out how to move asset(s) to a different volume. Also if I move it will that affect the entries that are using the asset?</p>

<p>Here's what im using to target the asset:
<code>$resourceImage = Asset::find()-&gt;volume('resourceImages')-&gt;filename($filename);</code></p>

<p>I need to move it to my <code>productImages</code> volume.</p>

<p>Thanks!</p>

<assets><craft3><element>
API - Update Asset Volume
# API - Update Asset Volume

(Asked by: username_0 on 2018-10-08)

Im trying to figure out how to move asset(s) to a different volume. Also if I move it will that affect the entries that are using the asset?

Here's what im using to target the asset:
`$resourceImage = Asset::find()->volume('resourceImages')->filename($filename);`

I need to move it to my `productImages` volume.

Thanks!

**Tags:** assets, craft3, element

---

## 1 answers

### Answer by username_1 on 2018-10-08. Score: 4 | Accepted answer

You can move them like this
$asset = Asset::find()->volume('resourceImages')->filename($filename)->one()
$folder = Craft::$app->getAssets()->findFolder(['volumeId' => X]);
Craft::$app->getAssets()->moveAsset($asset, $folder, $filename);

It won't change your relations or anything else in fact all the function does is:
/**
 * Move or rename an Asset.
 *
 * @param Asset $asset The asset whose file should be renamed
 * @param VolumeFolder $folder The Volume Folder to move the Asset to.
 * @param string $filename The new filename
 * @return bool Whether the asset was renamed successfully
 * @throws AssetLogicException if the asset’s volume is missing
 */
public function moveAsset(Asset $asset, VolumeFolder $folder, string $filename = ''): bool
{
    // Set the new combined target location, and save it
    $asset->newFilename = $filename;
    $asset->newFolderId = $folder->id;
    $asset->setScenario(Asset::SCENARIO_FILEOPS);

    return Craft::$app->getElements()->saveElement($asset);
}


---

