Excluir arquivos com o Cloud Storage em plataformas da Apple
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Depois de fazer upload de arquivos para o Cloud Storage, também é possível excluí-los.
Excluir um arquivo
Para excluir um arquivo, primeiro
crie uma referência
para ele. Em seguida, chame o método deleteWithCompletion: nessa referência.
Swift
// Create a reference to the file to deleteletdesertRef=storageRef.child("desert.jpg")do{// Delete the filetryawaitdesertRef.delete()}catch{// ...}
Objective-C
// Create a reference to the file to deleteFIRStorageReference*desertRef=[storageRefchild:@"images/desert.jpg"];// Delete the file[desertRefdeleteWithCompletion:^(NSError*error){if(error!=nil){// Uh-oh, an error occurred!}else{// File deleted successfully}}];
Lidar com erros
Há vários motivos para a ocorrência de erros em exclusões de arquivos. Por exemplo, talvez o arquivo não exista ou o usuário não tenha permissão para excluir o arquivo especificado. Saiba mais sobre erros na seção Solucionar erros.
[null,null,["Última atualização 2025-08-16 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/ios/create-reference)\nto that file. Then call the `deleteWithCompletion:` method on that reference. \n\nSwift \n\n```swift\n// Create a reference to the file to delete\nlet desertRef = storageRef.child(\"desert.jpg\")\n\ndo {\n // Delete the file\n try await desertRef.delete()\n} catch {\n // ...\n}\n \n```\n\nObjective-C \n\n```objective-c\n// Create a reference to the file to delete\nFIRStorageReference *desertRef = [storageRef child:@\"images/desert.jpg\"];\n\n// Delete the file\n[desertRef deleteWithCompletion:^(NSError *error){\n if (error != nil) {\n // Uh-oh, an error occurred!\n } else {\n // File deleted successfully\n }\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/ios/handle-errors)\nsection of the docs."]]