Supprimer des fichiers avec Cloud Storage for Unity
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Après avoir importé des fichiers dans Cloud Storage, vous pouvez également les supprimer.
Supprimer un fichier
Pour supprimer un fichier, commencez par créer une référence à ce fichier. Appelez ensuite la méthode DeleteAsync() sur cette référence.
// Create a reference to the file to delete.StorageReferencedesertRef=storageRef.Child("images/desert.jpg");// Delete the filedesertRef.DeleteAsync().ContinueWithOnMainThread(task=>{if(task.IsCompleted){Debug.Log("File deleted successfully.");}else{// Uh-oh, an error occurred!}});
Gérer les erreurs
Plusieurs raisons peuvent expliquer les erreurs de suppression de fichiers, y compris l'inexistence du fichier ou le manque d'autorisation de l'utilisateur pour supprimer le fichier spécifié. Pour en savoir plus sur les erreurs, consultez la section Gérer les erreurs de la documentation.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/08 (UTC).
[null,null,["Dernière mise à jour le 2025/08/08 (UTC)."],[],[],null,["\u003cbr /\u003e\n\nAfter uploading files to Cloud Storage, you can also delete them.\n| **Note:** By default, a Cloud Storage for Firebase bucket requires Firebase Authentication to perform any action on the bucket's data or files. You can change your Firebase Security Rules for Cloud Storage to [allow unauthenticated access for specific situations](/docs/storage/security/rules-conditions#public). However, for most situations, we strongly recommend [restricting access and setting up robust security rules](/docs/storage/security/get-started) (especially for production apps). Note that if you use Google App Engine and have a default Cloud Storage bucket with a name format of `*.appspot.com`, you may need to consider [how your security rules impact access to App Engine files](/docs/storage/gcp-integration#security-rules-and-app-engine-files).\n\nDelete a File\n\nTo delete a file, first\n[create a reference](/docs/storage/unity/create-reference)\nto that file. Then call the `DeleteAsync()` method on that reference. \n\n```c#\n// Create a reference to the file to delete.\nStorageReference desertRef = storageRef.Child(\"images/desert.jpg\");\n\n// Delete the file\ndesertRef.DeleteAsync().ContinueWithOnMainThread(task =\u003e {\n if (task.IsCompleted) {\n Debug.Log(\"File deleted successfully.\");\n }\n else {\n // Uh-oh, an error occurred!\n }\n});\n```\n| **Note:** Deleted files are typically recoverable for 7 days with [soft delete](https://cloud.google.com/storage/docs/soft-delete), which is enabled by default.\n\nHandle Errors\n\nThere are a number of reasons why errors may occur on file deletes,\nincluding the file not existing, or the user not having permission\nto delete the specified file. More information on errors can be found in the\n[Handle Errors](/docs/storage/unity/handle-errors)\nsection of the docs."]]